Class XStreamSerializer
- All Implemented Interfaces:
Serializer
- Since:
- 1.2
- Author:
- Allard Buijze
- See Also:
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedInstantiate aXStreamSerializerbased on the fields contained in theXStreamSerializer.Builder. -
Method Summary
Modifier and TypeMethodDescriptionstatic XStreamSerializer.Builderbuilder()Instantiate a Builder to be able to create aXStreamSerializer.static XStreamSerializerDeprecated.doDeserialize(SerializedObject serializedObject, com.thoughtworks.xstream.XStream xStream) Deserialize the givenserializedObject.protected <T> TdoSerialize(Object object, Class<T> expectedFormat, com.thoughtworks.xstream.XStream xStream) Serialize the givenobjectto the givenexpectedFormat.protected voidregisterConverters(ChainingConverter converter) Registers any converters that are specific to the type of content written by this serializer.Methods inherited from class org.axonframework.serialization.AbstractXStreamSerializer
addAlias, addFieldAlias, addPackageAlias, canSerializeTo, classForType, convert, deserialize, getCharset, getConverter, getXStream, serialize, typeForClass
-
Constructor Details
-
XStreamSerializer
Instantiate aXStreamSerializerbased on the fields contained in theXStreamSerializer.Builder. TheXStreaminstance is configured with several converters for the most common types in Axon.- Parameters:
builder- theXStreamSerializer.Builderused to instantiate aXStreamSerializerinstance
-
-
Method Details
-
builder
Instantiate a Builder to be able to create aXStreamSerializer.The
XStreamis defaulted to aXStream(HierarchicalStreamDriver)call, providing aCompactDriver, theCharsetis defaulted to aCharset.forName(String)using theUTF-8character set, theRevisionResolverdefaults to anAnnotationRevisionResolverand theConverterdefaults to aChainingConverter. Lastly, the builder adds Axon types for XStream's security settings by including"org.axonframework.**as a wildcard type. This can be disabled with theXStreamSerializer.Builder.disableAxonTypeSecurity()operation when required.Upon instantiation, several defaults aliases are added to the XStream instance, for example for the
GenericDomainEventMessage, theGenericCommandMessageand theMetaDataobjects among others. Additionally, a MetaData Converter is registered too. Lastly, if the provided Converter instance is of type ChainingConverter, then theregisterConverters(ChainingConverter)function will be called. This will register theDom4JToByteArrayConverter,InputStreamToDom4jConverter,XomToStringConverterandInputStreamToXomConverterto the Converter chain.- Returns:
- a Builder to be able to create a
XStreamSerializer
-
defaultSerializer
Deprecated.in favor of using thebuilder()to construct an instance using a configuredXStreaminstance. Using this shorthand still works, but will use anXStreaminstance that allows everything. Although this works, XStream expects the types or wildcards for the types to be defined to ensure the application stays secure. As such, it is highly recommended to follow their recommended approach.Instantiate a defaultXStreamSerializer.The
XStreamis defaulted to aXStream(HierarchicalStreamDriver)call, providing aCompactDriver, theCharsetis defaulted to aCharset.forName(String)using theUTF-8character set, theRevisionResolverdefaults to anAnnotationRevisionResolverand theConverterdefaults to aChainingConverter. Lastly, the builder adds Axon types for XStream's security settings by including"org.axonframework.**as a wildcard type.Upon instantiation, several defaults aliases are added to the XStream instance, for example for the
GenericDomainEventMessage, theGenericCommandMessageand theMetaDataobjects among others. Additionally, a MetaData Converter is registered too. Lastly, if the provided Converter instance is of type ChainingConverter, then theregisterConverters(ChainingConverter)function will be called. This will register theDom4JToByteArrayConverter,InputStreamToDom4jConverter,XomToStringConverterandInputStreamToXomConverterto the Converter chain.- Returns:
- a
XStreamSerializer
-
doSerialize
protected <T> T doSerialize(Object object, Class<T> expectedFormat, com.thoughtworks.xstream.XStream xStream) Description copied from class:AbstractXStreamSerializerSerialize the givenobjectto the givenexpectedFormat. The subclass may useAbstractXStreamSerializer.convert(Object, Class, Class)to convert the result of the serialization to the expected type.- Specified by:
doSerializein classAbstractXStreamSerializer- Type Parameters:
T- The format in which the serialized object must be returned- Parameters:
object- The object to serializeexpectedFormat- The format in which the serialized object must be returnedxStream- The XStream instance to serialize with- Returns:
- The serialized object
-
doDeserialize
public Object doDeserialize(SerializedObject serializedObject, com.thoughtworks.xstream.XStream xStream) Description copied from class:AbstractXStreamSerializerDeserialize the givenserializedObject.- Specified by:
doDeserializein classAbstractXStreamSerializer- Parameters:
serializedObject- The instance containing the serialized format of the objectxStream- The XStream instance to deserialize with- Returns:
- the deserialized object
-
registerConverters
Description copied from class:AbstractXStreamSerializerRegisters any converters that are specific to the type of content written by this serializer.- Specified by:
registerConvertersin classAbstractXStreamSerializer- Parameters:
converter- the Converter to register the converters with
-
builder()to construct an instance using a configuredXStreaminstance.