public void testElision() throws SerializationException { ObjectGraphTestServiceAsync async = getServiceAsync(); SerializationStreamWriter writer = ((SerializationStreamFactory) async) .createStreamWriter(); AbstractSerializationStream stream = (AbstractSerializationStream) writer; assertEquals( "Missing flag", expectedObfuscationState(), stream.hasFlags(AbstractSerializationStream.FLAG_ELIDE_TYPE_NAMES)); SerializableDoublyLinkedNode node = new SerializableDoublyLinkedNode(); writer.writeObject(node); String s = writer.toString(); // Don't use class.getName() due to conflict with removal of type names assertEquals("Checking for SerializableDoublyLinkedNode", expectedObfuscationState(), !s.contains("SerializableDoublyLinkedNode")); }
public <T> String serialize(Class<? super T> clazz, T instance, SerializationPolicy serializationPolicy) throws SerializationException { if (instance == null) { return null; }else if(String.class.equals(clazz)){ return (String) instance; } if (serializationPolicy == null) { throw new IllegalArgumentException("SerializationPolicy is null, please call StorageUtils.PolicyLoader.load(...) before"); } ServerSerializationStreamWriter stream = new ServerSerializationStreamWriter(serializationPolicy); stream.setFlags(AbstractSerializationStream.DEFAULT_FLAGS); stream.prepareToWrite(); if (clazz != void.class) { stream.serializeValue(instance, clazz); } return stream.toString(); }
public static String invokeAndEncodeResponse(Object target, Method serviceMethod, Object[] args, SerializationPolicy serializationPolicy) throws SerializationException { return invokeAndEncodeResponse(target, serviceMethod, args, serializationPolicy, AbstractSerializationStream.DEFAULT_FLAGS); }