Class JacksonSerializer
java.lang.Object
io.fluxzero.sdk.common.serialization.AbstractSerializer<com.fasterxml.jackson.databind.JsonNode>
io.fluxzero.sdk.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 Fluxzero, supporting:
- Serialization and deserialization using Jackson's
ObjectMapper - Integration with upcasters/downcasters for versioned data evolution
- Intermediate representation based on
JsonNodefor revision tracking DocumentSerializersupport 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.JsonMapperDefaultJsonMapperinstance 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 specificJsonMapperinstance.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.JsonNodeasIntermediateValue(Object input) Converts the given object into aJsonNodefor use in revision downcasting.protected StringReturns 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> VConverts an object into another type using Jackson’sObjectMapper.protected ObjectdoDeserialize(Data<?> data, String type) Deserializes aDatainstance 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> TfromDocument(SerializedDocument document) Deserializes the payload of the given document into a Java object using the type information contained in the document.<T> TfromDocument(SerializedDocument document, Class<T> type) Deserializes the payload of the given document into an instance of the specified type.protected StringgetCanonicalType(Type type) Computes the canonical string representation of aType.protected com.fasterxml.jackson.databind.JavaTypegetJavaType(String type) Resolves a canonicalJavaTypefor the given string-based type name.protected booleanisKnownType(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 AbstractSerializer
clone, convert, deserialize, deserializeOtherFormat, downcast, downcast, getType, getTypeString, registerDowncasters, registerTypeCaster, registerUpcasters, serialize, serializeToOtherFormat, upcastTypeMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ContentFilter
filterContentMethods inherited from interface DocumentSerializer
toDocumentMethods inherited from interface Serializer
deserialize, deserialize, deserializeMessage, deserializeMessages, deserializeMessages, deserializeMessages, deserializeMessages, registerCasters, serialize
-
Field Details
-
defaultObjectMapper
public static com.fasterxml.jackson.databind.json.JsonMapper defaultObjectMapperDefaultJsonMapperinstance 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
ModuleSPI (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 specificJsonMapperinstance. -
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:
asStringin classAbstractSerializer<com.fasterxml.jackson.databind.JsonNode>
-
doSerialize
Serializes the object to a JSON byte array.- Specified by:
doSerializein classAbstractSerializer<com.fasterxml.jackson.databind.JsonNode>- Throws:
Exception
-
doDeserialize
Deserializes aDatainstance into an object of the given type using the Jackson object mapper. SupportsJsonNode, byte arrays and strings as serialized input.- Specified by:
doDeserializein classAbstractSerializer<com.fasterxml.jackson.databind.JsonNode>- Throws:
Exception
-
asIntermediateValue
Converts the given object into aJsonNodefor use in revision downcasting.- Specified by:
asIntermediateValuein classAbstractSerializer<com.fasterxml.jackson.databind.JsonNode>
-
isKnownType
Determines whether the given type is known to the Jackson type system.- Overrides:
isKnownTypein classAbstractSerializer<com.fasterxml.jackson.databind.JsonNode>
-
deserializeUnknownType
Fallback handler for deserialization of unknown types. Attempts best-effort conversion using Jackson.- Overrides:
deserializeUnknownTypein classAbstractSerializer<com.fasterxml.jackson.databind.JsonNode>
-
getJavaType
Resolves a canonicalJavaTypefor the given string-based type name. -
getCanonicalType
-
toDocument
public SerializedDocument toDocument(Object value, String id, String collection, Instant timestamp, Instant end, Metadata metadata) Description copied from interface:DocumentSerializerSerializes a given value into aSerializedDocument, using the specified identifiers, timestamps, and metadata.- Specified by:
toDocumentin 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
SerializedDocumentrepresenting the given value
-
fromDocument
Description copied from interface:DocumentSerializerDeserializes the payload of the given document into a Java object using the type information contained in the document.- Specified by:
fromDocumentin interfaceDocumentSerializer- Type Parameters:
T- the target type- Parameters:
document- theSerializedDocumentto deserialize- Returns:
- the deserialized object
-
fromDocument
Description copied from interface:DocumentSerializerDeserializes the payload of the given document into an instance of the specified type.- Specified by:
fromDocumentin interfaceDocumentSerializer- Type Parameters:
T- the target type- Parameters:
document- theSerializedDocumentto deserializetype- the target class for deserialization- Returns:
- the deserialized object
-
doConvert
Converts an object into another type using Jackson’sObjectMapper.- Specified by:
doConvertin 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:
doClonein classAbstractSerializer<com.fasterxml.jackson.databind.JsonNode>
-