Interface DocumentSerializer

All Known Implementing Classes:
JacksonSerializer

public interface DocumentSerializer
Interface for converting domain objects to and from SerializedDocument instances for indexing and searching.

A DocumentSerializer defines how objects are transformed into a serializable structure suitable for Flux Capacitor's search infrastructure. Documents are associated with:

  • A unique ID (within a collection)
  • A collection name that groups similar documents
  • An optional timestamp indicating the start time of the document (for time-bounded documents)
  • An optional end timestamp (for time-bounded documents)
  • Optional metadata associated with the document

Implementations are typically used by the DocumentStore when indexing or retrieving documents.

This interface supports both serialization (toDocument(java.lang.Object, java.lang.String, java.lang.String, java.time.Instant, java.time.Instant)) and deserialization (fromDocument(io.fluxcapacitor.common.api.search.SerializedDocument)).

See Also:
  • Method Details

    • toDocument

      default SerializedDocument toDocument(Object value, String id, String collection, Instant timestamp, Instant end)
      Serializes a given value into a SerializedDocument, using the specified identifiers and timestamps.

      This is a convenience method that uses empty Metadata.

      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 optional timestamp marking the start of the document's relevance
      end - optional timestamp marking the end of the document's relevance
      Returns:
      a SerializedDocument representing the given value
    • toDocument

      SerializedDocument toDocument(Object value, String id, String collection, Instant timestamp, Instant end, Metadata metadata)
      Serializes a given value into a SerializedDocument, using the specified identifiers, timestamps, and metadata.
      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

      <T> T fromDocument(SerializedDocument document)
      Deserializes the payload of the given document into a Java object using the type information contained in the document.
      Type Parameters:
      T - the target type
      Parameters:
      document - the SerializedDocument to deserialize
      Returns:
      the deserialized object
    • fromDocument

      <T> T fromDocument(SerializedDocument document, Class<T> type)
      Deserializes the payload of the given document into an instance of the specified type.
      Type Parameters:
      T - the target type
      Parameters:
      document - the SerializedDocument to deserialize
      type - the target class for deserialization
      Returns:
      the deserialized object