|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.axonframework.serializer.AbstractXStreamSerializer
public abstract class AbstractXStreamSerializer
Abstract implementation for XStream based serializers. It provides some helper methods and configuration features independent of the actual format used to marshal to.
Constructor Summary | |
---|---|
protected |
AbstractXStreamSerializer(Charset charset,
com.thoughtworks.xstream.XStream xStream)
Initialize the serializer using the given charset and xStream instance. |
protected |
AbstractXStreamSerializer(Charset charset,
com.thoughtworks.xstream.XStream xStream,
RevisionResolver revisionResolver)
Initialize the serializer using the given charset and xStream instance. |
protected |
AbstractXStreamSerializer(Charset charset,
com.thoughtworks.xstream.XStream xStream,
RevisionResolver revisionResolver,
ConverterFactory converterFactory)
Initialize the serializer using the given charset , xStream instance,
revisionResolver and converterFactory . |
protected |
AbstractXStreamSerializer(com.thoughtworks.xstream.XStream xStream)
Initialize a generic serializer using the UTF-8 character set. |
protected |
AbstractXStreamSerializer(com.thoughtworks.xstream.XStream xStream,
RevisionResolver revisionResolver)
Initialize a generic serializer using the UTF-8 character set. |
Method Summary | ||
---|---|---|
void |
addAlias(String name,
Class type)
Adds an alias to use instead of the fully qualified class name. |
|
void |
addFieldAlias(String alias,
Class definedIn,
String fieldName)
Adds an alias to use for a given field in the given class. |
|
void |
addPackageAlias(String alias,
String pkgName)
Add an alias for a package. |
|
|
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. |
|
protected
|
convert(Class<S> sourceType,
Class<T> targetType,
S source)
Convert the given source , of type sourceType to the given targetType . |
|
|
deserialize(SerializedObject<S> serializedObject)
Deserializes the first object read from the given bytes . |
|
protected abstract Object |
doDeserialize(SerializedObject serializedObject,
com.thoughtworks.xstream.XStream xStream)
Deserialize the given serializedObject . |
|
protected abstract
|
doSerialize(Object object,
Class<T> expectedFormat,
com.thoughtworks.xstream.XStream xStream)
Serialize the given object to the given expectedFormat . |
|
Charset |
getCharset()
Returns the character set used to convert character to bytes and vice versa. |
|
ConverterFactory |
getConverterFactory()
Returns the ConverterFactory used by this serialized. |
|
com.thoughtworks.xstream.XStream |
getXStream()
Returns a reference to the underlying XStream instance, that does the actual
serialization. |
|
protected abstract void |
registerConverters(ChainingConverterFactory converterFactory)
Registers any converters that are specific to the type of content written by this serializer. |
|
|
serialize(Object object,
Class<T> expectedType)
Serialize the given object into a Serialized Object containing the given
expectedRepresentation . |
|
SerializedType |
typeForClass(Class type)
Returns the type identifier for the given class. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
protected AbstractXStreamSerializer(com.thoughtworks.xstream.XStream xStream)
AnnotationRevisionResolver
is used to resolve the revision for serialized objects.
xStream
- XStream instance to useprotected AbstractXStreamSerializer(com.thoughtworks.xstream.XStream xStream, RevisionResolver revisionResolver)
xStream
- XStream instance to userevisionResolver
- The strategy to use to resolve the revision of an objectprotected AbstractXStreamSerializer(Charset charset, com.thoughtworks.xstream.XStream xStream)
charset
and xStream
instance. The
xStream
instance is configured with several converters for the most common types in Axon.
An AnnotationRevisionResolver
is used to resolve revision for serialized objects.
charset
- The character set to usexStream
- The XStream instance to useprotected AbstractXStreamSerializer(Charset charset, com.thoughtworks.xstream.XStream xStream, RevisionResolver revisionResolver)
charset
and xStream
instance. The
xStream
instance is configured with several converters for the most common types in Axon.
charset
- The character set to usexStream
- The XStream instance to userevisionResolver
- The strategy to use to resolve the revision of an objectprotected AbstractXStreamSerializer(Charset charset, com.thoughtworks.xstream.XStream xStream, RevisionResolver revisionResolver, ConverterFactory converterFactory)
charset
, xStream
instance,
revisionResolver
and converterFactory
. The xStream
instance is configured
with several converters for the most common types in Axon.
charset
- The character set to usexStream
- The XStream instance to userevisionResolver
- The strategy to use to resolve the revision of an objectconverterFactory
- The ConverterFactory providing the necessary content convertersMethod Detail |
---|
protected abstract void registerConverters(ChainingConverterFactory converterFactory)
converterFactory
- the ConverterFactory to register the converters withpublic <T> boolean canSerializeTo(Class<T> expectedRepresentation)
Serializer
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.
canSerializeTo
in interface Serializer
T
- The type of data a Serialized Object should containexpectedRepresentation
- The type of data a Serialized Object should contain
true
if the expectedRepresentation
is supported, otherwise false
.public <T> SerializedObject<T> serialize(Object object, Class<T> expectedType)
object
into a Serialized Object containing the given
expectedRepresentation
.
Use Serializer.canSerializeTo(Class)
to detect whether the expectedRepresentation
is supported by
this serializer.
serialize
in interface Serializer
T
- The expected data type representing the serialized objectobject
- The object to serializeexpectedType
- The expected data type representing the serialized object
protected abstract <T> T doSerialize(Object object, Class<T> expectedFormat, com.thoughtworks.xstream.XStream xStream)
object
to the given expectedFormat
. The subclass may use convert(Class, Class, Object)
to convert the result of the serialization to the expected type.
T
- The format in which the serialized object must be returnedobject
- The object to serializeexpectedFormat
- The format in which the serialized object must be returnedxStream
- The XStream instance to serialize with
protected abstract Object doDeserialize(SerializedObject serializedObject, com.thoughtworks.xstream.XStream xStream)
serializedObject
.
serializedObject
- The instance containing the serialized format of the objectxStream
- The XStream instance to deserialize with
protected <S,T> T convert(Class<S> sourceType, Class<T> targetType, S source)
source
, of type sourceType
to the given targetType
.
S
- The type of data that needs to be convertedT
- The target type of the conversionsourceType
- The type of data that needs to be converted. Should be a content type identifier, not
necessarily the result of source.getClass()
.targetType
- The target type of the conversionsource
- The object to convert
public <S,T> T deserialize(SerializedObject<S> serializedObject)
bytes
. The bytes
are not consumed
from the array or modified in any way. The resulting object instance is cast to the expected type.
deserialize
in interface Serializer
S
- The data type of the serialized objectT
- The expected deserialized typeserializedObject
- the instance describing the type of object and the bytes providing the serialized data
public Class classForType(SerializedType type)
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.
classForType
in interface Serializer
type
- The type identifier of the object
public SerializedType typeForClass(Class type)
Serializer
Serializer.serialize(Object, Class)
.
typeForClass
in interface Serializer
type
- Class representing the type of the serializable Object.
public void addAlias(String name, Class type)
name
- The alias to usetype
- The Class to use the alias forXStream.alias(String, Class)
public void addPackageAlias(String alias, String pkgName)
alias
- The alias to use.pkgName
- The package to use the alias forXStream.aliasPackage(String, String)
public void addFieldAlias(String alias, Class definedIn, String fieldName)
alias
- The alias to use instead of the original field namedefinedIn
- The class that defines the field.fieldName
- The name of the field to use the alias forXStream.aliasField(String, Class, String)
public com.thoughtworks.xstream.XStream getXStream()
XStream
instance, that does the actual
serialization.
XStream
public Charset getCharset()
public ConverterFactory getConverterFactory()
getConverterFactory
in interface Serializer
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |