public abstract class AbstractXStreamSerializer extends Object implements Serializer
Modifier | Constructor and Description |
---|---|
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,
Converter converter)
Initialize the serializer using the given
charset , xStream instance,
revisionResolver and converter . |
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.
|
Modifier and Type | Method and Description |
---|---|
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.
|
<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.
|
protected <S,T> T |
convert(S source,
Class<S> sourceType,
Class<T> targetType)
Convert the given
source , of type sourceType to the given targetType . |
<S,T> T |
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 <T> T |
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.
|
Converter |
getConverter()
Returns the Converter 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(ChainingConverter converter)
Registers any converters that are specific to the type of content written by this serializer.
|
<T> SerializedObject<T> |
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.
|
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, Converter converter)
charset
, xStream
instance,
revisionResolver
and converter
. 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 objectconverter
- The converter providing the necessary content convertersprotected abstract void registerConverters(ChainingConverter converter)
converter
- the Converter 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 containtrue
if the expectedRepresentation
is supported, otherwise false
.public <T> SerializedObject<T> serialize(Object object, Class<T> expectedType)
Serializer
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 objectprotected abstract <T> T doSerialize(Object object, Class<T> expectedFormat, com.thoughtworks.xstream.XStream xStream)
object
to the given expectedFormat
. The subclass may use convert(Object, Class, Class)
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 withprotected 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 withprotected <S,T> T convert(S source, Class<S> sourceType, Class<T> targetType)
source
, of type sourceType
to the given targetType
.S
- The type of data that needs to be convertedT
- The target type of the conversionsource
- The object to convertsourceType
- The source type of the conversiontargetType
- The target type of the conversionpublic <S,T> T deserialize(SerializedObject<S> serializedObject)
Serializer
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 datapublic Class classForType(SerializedType type)
Serializer
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 objectpublic 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 Converter getConverter()
getConverter
in interface Serializer
Copyright © 2010–2018. All rights reserved.