Class AbstractXStreamSerializer.Builder

java.lang.Object
org.axonframework.serialization.AbstractXStreamSerializer.Builder
Direct Known Subclasses:
XStreamSerializer.Builder
Enclosing class:
AbstractXStreamSerializer

public abstract static class AbstractXStreamSerializer.Builder extends Object
Abstract Builder class to instantiate AbstractXStreamSerializer.

The Charset is defaulted to a Charset.forName(String) using the UTF-8 character set, the RevisionResolver defaults to an AnnotationRevisionResolver and the Converter defaults to a ChainingConverter. The XStream is a hard requirement and as such should be provided. Lastly, the builder adds Axon types for XStream's security settings by including "org.axonframework.** as a wildcard type. This can be disabled with the disableAxonTypeSecurity() operation when required.

Upon instantiation, several defaults aliases are added to the XStream instance, for example for the GenericDomainEventMessage, the GenericCommandMessage and the MetaData objects among others. Additionally, a MetaData Converter is registered too. Lastly, if the provided Converter instance is of type ChainingConverter, then the AbstractXStreamSerializer.registerConverters(ChainingConverter) function will be called. Depending on the AbstractXStreamSerializer, this will add a number of Converter instances to the chain.

  • Field Details

    • xStream

      protected com.thoughtworks.xstream.XStream xStream
  • Constructor Details

    • Builder

      public Builder()
  • Method Details

    • xStream

      public AbstractXStreamSerializer.Builder xStream(@Nonnull com.thoughtworks.xstream.XStream xStream)
      Sets the XStream used to perform the serialization of objects to XML, and vice versa.
      Parameters:
      xStream - the XStream used to perform the serialization of objects to XML, and vice versa
      Returns:
      the current Builder instance, for fluent interfacing
    • charset

      public AbstractXStreamSerializer.Builder charset(@Nonnull Charset charset)
      Sets the Charset used for the in- and output streams required by XStream for the to and from xml function calls. Defaults to a Charset.forName(String) using the UTF-8 character set.
      Parameters:
      charset - the Charset used for the in- and output streams required by XStream
      Returns:
      the current Builder instance, for fluent interfacing
    • revisionResolver

      public AbstractXStreamSerializer.Builder revisionResolver(@Nonnull RevisionResolver revisionResolver)
      Sets the RevisionResolver used to resolve the revision from an object to be serialized. Defaults to an AnnotationRevisionResolver which resolves the revision based on the contents of the Revision annotation on the serialized classes.
      Parameters:
      revisionResolver - a RevisionResolver used to resolve the revision from an object to be serialized
      Returns:
      the current Builder instance, for fluent interfacing
    • converter

      public AbstractXStreamSerializer.Builder converter(@Nonnull Converter converter)
      Sets the Converter used as a converter factory providing converter instances utilized by upcasters to convert between different content types. Defaults to a ChainingConverter.
      Parameters:
      converter - a Converter used as a converter factory providing converter instances utilized by upcasters to convert between different content types
      Returns:
      the current Builder instance, for fluent interfacing
    • classLoader

      public AbstractXStreamSerializer.Builder classLoader(@Nonnull ClassLoader classLoader)
      Sets the ClassLoader used as an override for default ClassLoader used in the XStream. The same solution could thus be achieved by configuring the `XStream` instance directly.
      Parameters:
      classLoader - a ClassLoader used as a class loader in XStream
      Returns:
      the current Builder instance, for fluent interfacing
    • lenientDeserialization

      public AbstractXStreamSerializer.Builder lenientDeserialization()
      Configures the underlying XStream instance to be lenient when deserializing data into Java objects. Specifically sets the XStream.ignoreUnknownElements().
      Returns:
      the current Builder instance, for fluent interfacing
    • disableAxonTypeSecurity

      public AbstractXStreamSerializer.Builder disableAxonTypeSecurity()
      Configures the underlying XStream instance to not include Axon's classes by default. Concretely, the XStream.allowTypesByWildcard(String[]) method will not be invoked with "org.axonframework.**".

      It is recommended to disable this setting when complete control is required over the allowed types in this serializer's XStream instance.

      Returns:
      the current Builder instance for fluent interfacing
    • disableCachingOfUnknownClasses

      public AbstractXStreamSerializer.Builder disableCachingOfUnknownClasses()
      Disables the caching of the names for classes which couldn't be resolved to a class.

      It is recommended to disable this in case the class loading is dynamic, and classes that are not available at one point in time, may become available at any time later.

      Returns:
      the current Builder instance, for fluent interfacing
    • validate

      protected void validate() throws AxonConfigurationException
      Validates whether the fields contained in this Builder are set accordingly.
      Throws:
      AxonConfigurationException - if one field is asserted to be incorrect according to the Builder's specifications