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 Summary
Modifier and TypeMethodDescription<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.default SerializedDocument
Serializes a given value into aSerializedDocument
, using the specified identifiers and timestamps.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.
-
Method Details
-
toDocument
default SerializedDocument toDocument(Object value, String id, String collection, Instant timestamp, Instant end) Serializes a given value into aSerializedDocument
, using the specified identifiers and timestamps.This is a convenience method that uses empty
Metadata
.- Parameters:
value
- the value to be serializedid
- the unique identifier of the document (within the collection)collection
- the name of the document collectiontimestamp
- the optional timestamp marking the start of the document's relevanceend
- 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 aSerializedDocument
, using the specified identifiers, timestamps, and metadata.- 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
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
- theSerializedDocument
to deserialize- Returns:
- the deserialized object
-
fromDocument
Deserializes the payload of the given document into an instance of the specified type.- Type Parameters:
T
- the target type- Parameters:
document
- theSerializedDocument
to deserializetype
- the target class for deserialization- Returns:
- the deserialized object
-