Class JacksonSerializer
java.lang.Object
io.fluxcapacitor.javaclient.common.serialization.AbstractSerializer<com.fasterxml.jackson.databind.JsonNode>
io.fluxcapacitor.javaclient.common.serialization.jackson.JacksonSerializer
- All Implemented Interfaces:
ContentFilter
,Serializer
,DocumentSerializer
public class JacksonSerializer
extends AbstractSerializer<com.fasterxml.jackson.databind.JsonNode>
implements DocumentSerializer
A concrete
Serializer
implementation based on Jackson.
This is the default serializer used in Flux Capacitor, supporting:
- Serialization and deserialization using Jackson's
ObjectMapper
- Integration with upcasters/downcasters for versioned data evolution
- Intermediate representation based on
JsonNode
for revision tracking DocumentSerializer
support for document store interoperability- Type caching and memoization for performance
You can customize or replace this serializer entirely by subclassing or injecting your own implementation of
AbstractSerializer
.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic com.fasterxml.jackson.databind.json.JsonMapper
DefaultJsonMapper
instance used for JSON serialization and deserialization. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a default JacksonSerializer with no up/downcasters.JacksonSerializer
(com.fasterxml.jackson.databind.json.JsonMapper objectMapper) Constructs a JacksonSerializer with a specificJsonMapper
instance.JacksonSerializer
(com.fasterxml.jackson.databind.json.JsonMapper objectMapper, Collection<?> casterCandidates) Constructs a JacksonSerializer with an object mapper and up/downcaster candidates.JacksonSerializer
(com.fasterxml.jackson.databind.json.JsonMapper objectMapper, Collection<?> casterCandidates, JacksonInverter inverter) Full constructor with object mapper, caster candidates and custom document inverter.JacksonSerializer
(Collection<?> casterCandidates) Constructs a JacksonSerializer with the given up/downcaster candidates. -
Method Summary
Modifier and TypeMethodDescriptionprotected com.fasterxml.jackson.databind.JsonNode
asIntermediateValue
(Object input) Converts the given object into aJsonNode
for use in revision downcasting.protected String
Returns a canonical string name for the given type.protected Stream
<DeserializingObject<byte[], ?>> Fallback handler for deserialization of unknown types.Performs a field-level clone by copying values from the original object into a new instance of the same type.<V> V
Converts an object into another type using Jackson’sObjectMapper
.protected Object
doDeserialize
(Data<?> data, String type) Deserializes aData
instance into an object of the given type using the Jackson object mapper.protected byte[]
doSerialize
(Object object) Serializes the object to a JSON byte array.<T> T
fromDocument
(SerializedDocument document) Deserializes the payload of the given document into a Java object using the type information contained in the document.<T> T
fromDocument
(SerializedDocument document, Class<T> type) Deserializes the payload of the given document into an instance of the specified type.protected String
getCanonicalType
(Type type) Computes the canonical string representation of aType
.protected com.fasterxml.jackson.databind.JavaType
getJavaType
(String type) Resolves a canonicalJavaType
for the given string-based type name.protected boolean
isKnownType
(String type) Determines whether the given type is known to the Jackson type system.toDocument
(Object value, String id, String collection, Instant timestamp, Instant end, Metadata metadata) Serializes a given value into aSerializedDocument
, using the specified identifiers, timestamps, and metadata.Methods inherited from class io.fluxcapacitor.javaclient.common.serialization.AbstractSerializer
clone, convert, deserialize, deserializeOtherFormat, downcast, downcast, getType, getTypeString, registerDowncasters, registerTypeCaster, registerUpcasters, serialize, serializeToOtherFormat, upcastType
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.fluxcapacitor.javaclient.common.serialization.ContentFilter
filterContent
Methods inherited from interface io.fluxcapacitor.javaclient.persisting.search.DocumentSerializer
toDocument
Methods inherited from interface io.fluxcapacitor.javaclient.common.serialization.Serializer
deserialize, deserialize, deserializeMessage, deserializeMessages, deserializeMessages, deserializeMessages, deserializeMessages, registerCasters, serialize
-
Field Details
-
defaultObjectMapper
public static com.fasterxml.jackson.databind.json.JsonMapper defaultObjectMapperDefaultJsonMapper
instance used for JSON serialization and deserialization.In advanced scenarios, users may replace this field with a custom
JsonMapper
. However, this is generally discouraged unless strictly necessary.A better approach for customizing Jackson behavior is to provide your own modules via the Jackson
Module
SPI (ServiceLoader mechanism), which avoids overriding global configuration and ensures compatibility.Warning: This mapper is also used to construct and parse search documents. Misconfiguration may result in inconsistencies in search indexing or data loss.
-
-
Constructor Details
-
JacksonSerializer
public JacksonSerializer()Constructs a default JacksonSerializer with no up/downcasters. -
JacksonSerializer
Constructs a JacksonSerializer with the given up/downcaster candidates. -
JacksonSerializer
public JacksonSerializer(com.fasterxml.jackson.databind.json.JsonMapper objectMapper) Constructs a JacksonSerializer with a specificJsonMapper
instance. -
JacksonSerializer
public JacksonSerializer(com.fasterxml.jackson.databind.json.JsonMapper objectMapper, Collection<?> casterCandidates) Constructs a JacksonSerializer with an object mapper and up/downcaster candidates. -
JacksonSerializer
public JacksonSerializer(com.fasterxml.jackson.databind.json.JsonMapper objectMapper, Collection<?> casterCandidates, JacksonInverter inverter) Full constructor with object mapper, caster candidates and custom document inverter.
-
-
Method Details
-
asString
Returns a canonical string name for the given type.- Overrides:
asString
in classAbstractSerializer<com.fasterxml.jackson.databind.JsonNode>
-
doSerialize
Serializes the object to a JSON byte array.- Specified by:
doSerialize
in classAbstractSerializer<com.fasterxml.jackson.databind.JsonNode>
- Throws:
Exception
-
doDeserialize
Deserializes aData
instance into an object of the given type using the Jackson object mapper. SupportsJsonNode
, byte arrays and strings as serialized input.- Specified by:
doDeserialize
in classAbstractSerializer<com.fasterxml.jackson.databind.JsonNode>
- Throws:
Exception
-
asIntermediateValue
Converts the given object into aJsonNode
for use in revision downcasting.- Specified by:
asIntermediateValue
in classAbstractSerializer<com.fasterxml.jackson.databind.JsonNode>
-
isKnownType
Determines whether the given type is known to the Jackson type system.- Overrides:
isKnownType
in classAbstractSerializer<com.fasterxml.jackson.databind.JsonNode>
-
deserializeUnknownType
Fallback handler for deserialization of unknown types. Attempts best-effort conversion using Jackson.- Overrides:
deserializeUnknownType
in classAbstractSerializer<com.fasterxml.jackson.databind.JsonNode>
-
getJavaType
Resolves a canonicalJavaType
for the given string-based type name. -
getCanonicalType
Computes the canonical string representation of aType
. -
toDocument
public SerializedDocument toDocument(Object value, String id, String collection, Instant timestamp, Instant end, Metadata metadata) Description copied from interface:DocumentSerializer
Serializes a given value into aSerializedDocument
, using the specified identifiers, timestamps, and metadata.- Specified by:
toDocument
in interfaceDocumentSerializer
- Parameters:
value
- the value to be serializedid
- the unique identifier of the document (within the collection)collection
- the name of the document collectiontimestamp
- the timestamp marking the start of the document's relevanceend
- optional timestamp marking the end of the document's relevancemetadata
- additional metadata to include with the document- Returns:
- a
SerializedDocument
representing the given value
-
fromDocument
Description copied from interface:DocumentSerializer
Deserializes the payload of the given document into a Java object using the type information contained in the document.- Specified by:
fromDocument
in interfaceDocumentSerializer
- Type Parameters:
T
- the target type- Parameters:
document
- theSerializedDocument
to deserialize- Returns:
- the deserialized object
-
fromDocument
Description copied from interface:DocumentSerializer
Deserializes the payload of the given document into an instance of the specified type.- Specified by:
fromDocument
in interfaceDocumentSerializer
- Type Parameters:
T
- the target type- Parameters:
document
- theSerializedDocument
to deserializetype
- the target class for deserialization- Returns:
- the deserialized object
-
doConvert
Converts an object into another type using Jackson’sObjectMapper
.- Specified by:
doConvert
in classAbstractSerializer<com.fasterxml.jackson.databind.JsonNode>
-
doClone
Performs a field-level clone by copying values from the original object into a new instance of the same type. This first converts the value to anObjectNode
.- Specified by:
doClone
in classAbstractSerializer<com.fasterxml.jackson.databind.JsonNode>
-