Class Jackson3Serializer.Builder

java.lang.Object
org.axonframework.serialization.jackson3.Jackson3Serializer.Builder
Enclosing class:
Jackson3Serializer

public static class Jackson3Serializer.Builder extends Object
Builder class to instantiate a Jackson3Serializer.

The RevisionResolver is defaulted to an AnnotationRevisionResolver, the Converter to a ChainingConverter and the ClassLoader to the ClassLoader of this class.

Upon instantiation, the created ObjectMapper will have the MetaDataDeserializer registered to it. Lastly, if the provided converter is of type ChainingConverter, the Jackson3Serializer.registerConverters(org.axonframework.serialization.ChainingConverter) is performed to automatically add the JsonNodeToByteArrayConverter and ByteArrayToJsonNodeConverter.

  • Constructor Details

    • Builder

      public Builder()
  • Method Details

    • revisionResolver

      public Jackson3Serializer.Builder revisionResolver(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 Jackson3Serializer.Builder converter(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
    • jsonMapperBuilderCustomizer

      public Jackson3Serializer.Builder jsonMapperBuilderCustomizer(Jackson3SerializerCustomizer customizer)
      Sets a customizer for the JsonMapper.Builder used to construct the final ObjectMapper. This customizer is called after all Axon configuration has been applied. Setting this value to null removes a previous customizer if any.
      Parameters:
      customizer - a customizer that is called just before the final ObjectMapper is constructed
      Returns:
      the current Builder instance, for fluent interfacing
    • classLoader

      public Jackson3Serializer.Builder classLoader(ClassLoader classLoader)
      Configures the TypeFactory to use the given ClassLoader when building the ObjectMapper. This may also be done in a customizer.
      Parameters:
      classLoader - the ClassLoader used to load classes with when deserializing
      Returns:
      the current Builder instance, for fluent interfacing
      See Also:
      • invalid reference
        #objectMapper(ObjectMapper)
      • TypeFactory.withClassLoader(ClassLoader)
    • lenientDeserialization

      public Jackson3Serializer.Builder lenientDeserialization()
      Configures the serializer to be lenient when when deserializing JSON into Java objects. Specifically, enables the DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY and DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS, and disables DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES. This may also be done in a customizer.
      Returns:
      the current Builder instance, for fluent interfacing
    • disableCachingOfUnknownClasses

      public Jackson3Serializer.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
    • defaultTyping

      public Jackson3Serializer.Builder defaultTyping()
      Configures the underlying ObjectMapper to include type information when serializing Java objects into JSON by activating default typing.

      Specifically, it uses

      invalid reference
      ObjectMapper#activateDefaultTyping(PolymorphicTypeValidator, ObjectMapper.DefaultTyping)
      with
      invalid reference
      ObjectMapper.DefaultTyping#NON_CONCRETE_AND_ARRAYS
      . To comply with Jackson 3 security requirements, this enables a BasicPolymorphicTypeValidator that allows all subtypes (via Object.class base type validation).

      This allows Collections and other non-concrete types to include type information automatically without requiring JsonTypeInfo annotations on the classes themselves.

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

      public Jackson3Serializer build()
      Initializes a Jackson3Serializer as specified through this Builder.
      Returns:
      a Jackson3Serializer as specified through this Builder
    • 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