org.axonframework.serializer
Interface Serializer

All Known Implementing Classes:
AbstractXStreamSerializer, DBObjectXStreamSerializer, DBObjectXStreamSerializer, JacksonSerializer, JavaSerializer, MessageSerializer, XStreamSerializer

public interface Serializer

Interface describing a serialization mechanism. Implementations can serialize objects of given type T to an output stream and read the object back in from an input stream.

Since:
1.2
Author:
Allard Buijze

Method Summary
<T> boolean
canSerializeTo(Class<T> expectedRepresentation)
          Indicates whether this Serializer is capable of serializing to the given expectedRepresentation.
 Class classForType(SerializedType type)
          Returns the class for the given type identifier.
<S,T> T
deserialize(SerializedObject<S> serializedObject)
          Deserializes the first object read from the given bytes.
 ConverterFactory getConverterFactory()
          Returns the converter factory used by this Serializer to convert between serialized representations.
<T> SerializedObject<T>
serialize(Object object, Class<T> expectedRepresentation)
          Serialize the given object into a Serialized Object containing the given expectedRepresentation.
 SerializedType typeForClass(Class type)
          Returns the type identifier for the given class.
 

Method Detail

serialize

<T> SerializedObject<T> serialize(Object object,
                                  Class<T> expectedRepresentation)
Serialize the given object into a Serialized Object containing the given expectedRepresentation.

Use canSerializeTo(Class) to detect whether the expectedRepresentation is supported by this serializer.

Type Parameters:
T - The expected data type representing the serialized object
Parameters:
object - The object to serialize
expectedRepresentation - The expected data type representing the serialized object
Returns:
the instance representing the serialized object.

canSerializeTo

<T> boolean canSerializeTo(Class<T> expectedRepresentation)
Indicates whether this Serializer is capable of serializing to the given expectedRepresentation.

When true, this does *not* guarantee that the serialization and (optional) conversion will also succeed when executed. For example, when a serializer produces a byte[] containing JSON, trying to convert to a Dom4J Document will fail, even though this serializer has a converter to convert byte[] to Dom4J instances.

Type Parameters:
T - The type of data a Serialized Object should contain
Parameters:
expectedRepresentation - The type of data a Serialized Object should contain
Returns:
true if the expectedRepresentation is supported, otherwise false.

deserialize

<S,T> T deserialize(SerializedObject<S> serializedObject)
Deserializes the first object read from the given bytes. The bytes are not consumed from the array or modified in any way. The resulting object instance is cast to the expected type.

Type Parameters:
S - The data type of the serialized object
T - The expected deserialized type
Parameters:
serializedObject - the instance describing the type of object and the bytes providing the serialized data
Returns:
the serialized object, cast to the expected type
Throws:
ClassCastException - if the first object in the stream is not an instance of <T>.

classForType

Class classForType(SerializedType type)
                   throws UnknownSerializedTypeException
Returns the class for the given type identifier. The result of this method must guarantee that the deserialized SerializedObject with the given type is an instance of the returned Class.

If a class cannot be resolved (i.e. because the class is not available on this JVM's classpath) this method throws UnknownSerializedTypeException.

Parameters:
type - The type identifier of the object
Returns:
the Class representing the type of the serialized Object
Throws:
UnknownSerializedTypeException - if the type cannot be resolved to a class

typeForClass

SerializedType typeForClass(Class type)
Returns the type identifier for the given class. This is the type identifier of the Serialized object as returned by serialize(Object, Class).

Parameters:
type - Class representing the type of the serializable Object.
Returns:
The type identifier of the object

getConverterFactory

ConverterFactory getConverterFactory()
Returns the converter factory used by this Serializer to convert between serialized representations. Generally, this ConverterFactory depends on the type of data the serializer serializes to.

Returns:
the converter factory used by this Serializer


Copyright © 2010-2016. All Rights Reserved.