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 Details

    • defaultObjectMapper

      public static com.fasterxml.jackson.databind.json.JsonMapper defaultObjectMapper
      Default JsonMapper 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

      public JacksonSerializer(Collection<?> casterCandidates)
      Constructs a JacksonSerializer with the given up/downcaster candidates.
    • JacksonSerializer

      public JacksonSerializer(com.fasterxml.jackson.databind.json.JsonMapper objectMapper)
      Constructs a JacksonSerializer with a specific JsonMapper 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

      protected String asString(Type type)
      Returns a canonical string name for the given type.
      Overrides:
      asString in class AbstractSerializer<com.fasterxml.jackson.databind.JsonNode>
    • doSerialize

      protected byte[] doSerialize(Object object) throws Exception
      Serializes the object to a JSON byte array.
      Specified by:
      doSerialize in class AbstractSerializer<com.fasterxml.jackson.databind.JsonNode>
      Throws:
      Exception
    • doDeserialize

      protected Object doDeserialize(Data<?> data, String type) throws Exception
      Deserializes a Data instance into an object of the given type using the Jackson object mapper. Supports JsonNode, byte arrays and strings as serialized input.
      Specified by:
      doDeserialize in class AbstractSerializer<com.fasterxml.jackson.databind.JsonNode>
      Throws:
      Exception
    • asIntermediateValue

      protected com.fasterxml.jackson.databind.JsonNode asIntermediateValue(Object input)
      Converts the given object into a JsonNode for use in revision downcasting.
      Specified by:
      asIntermediateValue in class AbstractSerializer<com.fasterxml.jackson.databind.JsonNode>
    • isKnownType

      protected boolean isKnownType(String type)
      Determines whether the given type is known to the Jackson type system.
      Overrides:
      isKnownType in class AbstractSerializer<com.fasterxml.jackson.databind.JsonNode>
    • deserializeUnknownType

      protected Stream<DeserializingObject<byte[],?>> deserializeUnknownType(SerializedObject<?> s)
      Fallback handler for deserialization of unknown types. Attempts best-effort conversion using Jackson.
      Overrides:
      deserializeUnknownType in class AbstractSerializer<com.fasterxml.jackson.databind.JsonNode>
    • getJavaType

      protected com.fasterxml.jackson.databind.JavaType getJavaType(String type)
      Resolves a canonical JavaType for the given string-based type name.
    • getCanonicalType

      protected String getCanonicalType(Type type)
      Computes the canonical string representation of a Type.
    • 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 a SerializedDocument, using the specified identifiers, timestamps, and metadata.
      Specified by:
      toDocument in interface DocumentSerializer
      Parameters:
      value - the value to be serialized
      id - the unique identifier of the document (within the collection)
      collection - the name of the document collection
      timestamp - the timestamp marking the start of the document's relevance
      end - optional timestamp marking the end of the document's relevance
      metadata - additional metadata to include with the document
      Returns:
      a SerializedDocument representing the given value
    • fromDocument

      public <T> T fromDocument(SerializedDocument document)
      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 interface DocumentSerializer
      Type Parameters:
      T - the target type
      Parameters:
      document - the SerializedDocument to deserialize
      Returns:
      the deserialized object
    • fromDocument

      public <T> T fromDocument(SerializedDocument document, Class<T> type)
      Description copied from interface: DocumentSerializer
      Deserializes the payload of the given document into an instance of the specified type.
      Specified by:
      fromDocument in interface DocumentSerializer
      Type Parameters:
      T - the target type
      Parameters:
      document - the SerializedDocument to deserialize
      type - the target class for deserialization
      Returns:
      the deserialized object
    • doConvert

      public <V> V doConvert(Object value, Type type)
      Converts an object into another type using Jackson’s ObjectMapper.
      Specified by:
      doConvert in class AbstractSerializer<com.fasterxml.jackson.databind.JsonNode>
    • doClone

      public Object doClone(Object value)
      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 an ObjectNode.
      Specified by:
      doClone in class AbstractSerializer<com.fasterxml.jackson.databind.JsonNode>