public static class JacksonSerializer.Builder extends Object
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 and Description |
---|
Builder() |
Modifier and Type | Method and Description |
---|---|
JacksonSerializer |
build()
Initializes a
JacksonSerializer as specified through this Builder. |
JacksonSerializer.Builder |
classLoader(ClassLoader classLoader)
|
JacksonSerializer.Builder |
converter(Converter converter)
Sets the
Converter used as a converter factory providing converter instances utilized by upcasters to
convert between different content types. |
JacksonSerializer.Builder |
defaultTyping()
Configures the underlying
ObjectMapper to include type information when serializing Java objects into
JSON. |
JacksonSerializer.Builder |
lenientDeserialization()
Configures the underlying ObjectMapper to be lenient when deserializing JSON into Java objects.
|
JacksonSerializer.Builder |
objectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
Sets the
ObjectMapper used to serialize and parse the objects to JSON. |
JacksonSerializer.Builder |
revisionResolver(RevisionResolver revisionResolver)
Sets the
RevisionResolver used to resolve the revision from an object to be serialized. |
protected void |
validate()
Validates whether the fields contained in this Builder are set accordingly.
|
public JacksonSerializer.Builder revisionResolver(RevisionResolver revisionResolver)
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.revisionResolver
- a RevisionResolver
used to resolve the revision from an object to be
serializedpublic JacksonSerializer.Builder converter(Converter converter)
Converter
used as a converter factory providing converter instances utilized by upcasters to
convert between different content types. Defaults to a ChainingConverter
.converter
- a Converter
used as a converter factory providing converter instances utilized by
upcasters to convert between different content typespublic JacksonSerializer.Builder objectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
ObjectMapper
used to serialize and parse the objects to JSON. This ObjectMapper allows for
customization of the serialized form. Defaults to the output of ObjectMapper()
.objectMapper
- an ObjectMapper
used to serialize and parse the objects to JSONpublic JacksonSerializer.Builder classLoader(ClassLoader classLoader)
ClassLoader
used as an override for default ClassLoader
used in the ObjectMapper
. The same solution could thus be achieved by configuring the `ObjectMapper` instance directly.classLoader
- the ClassLoader
used to load classes with when deserializingobjectMapper(ObjectMapper)
,
TypeFactory.withClassLoader(ClassLoader)
public JacksonSerializer.Builder lenientDeserialization()
DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY
and DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS
, and disables DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES
.public JacksonSerializer.Builder defaultTyping()
ObjectMapper
to include type information when serializing Java objects into
JSON. Specifically, it calls ObjectMapper.enableDefaultTyping(ObjectMapper.DefaultTyping)
method,
using ObjectMapper.DefaultTyping#NON_CONCRETE_AND_ARRAYS
. This can be toggled on to allow Collection
s of objects, for example query List
responses, to automatically
include the types without require the use of JsonTypeInfo
on the
objects themselves.public JacksonSerializer build()
JacksonSerializer
as specified through this Builder.JacksonSerializer
as specified through this Builderprotected void validate() throws AxonConfigurationException
AxonConfigurationException
- if one field is asserted to be incorrect according to the Builder's
specificationsCopyright © 2010–2024. All rights reserved.