Class JacksonSerializer.Builder
- Enclosing class:
JacksonSerializer
JacksonSerializer.
The RevisionResolver is defaulted to an AnnotationRevisionResolver, the Converter to a
ChainingConverter, the ObjectMapper defaults to a ObjectMapper() result and
the ClassLoader to the ClassLoader of this class.
Upon instantiation, the ObjectMapper will get two modules registered to it by default, (1) the MetaDataDeserializer and the (2) JavaTimeModule. Lastly, if the provided converter is of type
ChainingConverter, the JacksonSerializer.registerConverters(org.axonframework.serialization.ChainingConverter) is performed to automatically add the JsonNodeToByteArrayConverter and ByteArrayToJsonNodeConverter.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuild()Initializes aJacksonSerializeras specified through this Builder.classLoader(ClassLoader classLoader) Sets theConverterused as a converter factory providing converter instances utilized by upcasters to convert between different content types.Configures the underlyingObjectMapperto include type information when serializing Java objects into JSON.Disables the caching of the names for classes which couldn't be resolved to a class.Configures the underlying ObjectMapper to be lenient when deserializing JSON into Java objects.objectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper) Sets theObjectMapperused to serialize and parse the objects to JSON.revisionResolver(RevisionResolver revisionResolver) Sets theRevisionResolverused to resolve the revision from an object to be serialized.protected voidvalidate()Validates whether the fields contained in this Builder are set accordingly.
-
Constructor Details
-
Builder
public Builder()
-
-
Method Details
-
revisionResolver
Sets theRevisionResolverused to resolve the revision from an object to be serialized. Defaults to anAnnotationRevisionResolverwhich resolves the revision based on the contents of theRevisionannotation on the serialized classes.- Parameters:
revisionResolver- aRevisionResolverused to resolve the revision from an object to be serialized- Returns:
- the current Builder instance, for fluent interfacing
-
converter
Sets theConverterused as a converter factory providing converter instances utilized by upcasters to convert between different content types. Defaults to aChainingConverter.- Parameters:
converter- aConverterused as a converter factory providing converter instances utilized by upcasters to convert between different content types- Returns:
- the current Builder instance, for fluent interfacing
-
objectMapper
public JacksonSerializer.Builder objectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper) Sets theObjectMapperused to serialize and parse the objects to JSON. This ObjectMapper allows for customization of the serialized form. Defaults to the output ofObjectMapper().- Parameters:
objectMapper- anObjectMapperused to serialize and parse the objects to JSON- Returns:
- the current Builder instance, for fluent interfacing
-
classLoader
Sets theClassLoaderused as an override for defaultClassLoaderused in theObjectMapper. The same solution could thus be achieved by configuring the `ObjectMapper` instance directly.- Parameters:
classLoader- theClassLoaderused to load classes with when deserializing- Returns:
- the current Builder instance, for fluent interfacing
- See Also:
-
lenientDeserialization
Configures the underlying ObjectMapper to be lenient when deserializing JSON into Java objects. Specifically, enables theDeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAYandDeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS, and disablesDeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES.- Returns:
- the current Builder instance, for fluent interfacing
-
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
Configures the underlyingObjectMapperto include type information when serializing Java objects into JSON. Specifically, it callsObjectMapper.enableDefaultTyping(ObjectMapper.DefaultTyping)method, usingObjectMapper.DefaultTyping.NON_CONCRETE_AND_ARRAYS. This can be toggled on to allowCollections of objects, for example queryListresponses, to automatically include the types without require the use ofJsonTypeInfoon the objects themselves.- Returns:
- the current Builder instance, for fluent interfacing
-
build
Initializes aJacksonSerializeras specified through this Builder.- Returns:
- a
JacksonSerializeras specified through this Builder
-
validate
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
-