Interface Serializer
- All Superinterfaces:
ContentFilter
- All Known Implementing Classes:
AbstractSerializer, JacksonSerializer, ProxySerializer
byte[] representations.
A Serializer transforms Java objects into Data containers (holding raw byte arrays) and restores them
back, optionally using format hints or handling type revisions via upcasting/downcasting.
It also provides lazy deserialization and registration hooks for custom (de)casters. This makes it central to Fluxzero’s persistence, transport, and replay systems.
Responsibilities
- Serialize objects with optional format hints
- Deserialize to objects or messages, lazily if needed
- Support revisioned types via upcasting and downcasting
- Enable flexible error strategies for unknown types
- See Also:
-
Method Summary
Modifier and TypeMethodDescription<V> VCreates a deep copy of the given object using serialization.<V> VConverts a given object to another type using the serializer's object mapping rules.default <T> Tdeserialize(SerializedObject<byte[]> data) Upcasts and deserializes the givenDataobject to an object of type T.default <T> Tdeserialize(SerializedObject<byte[]> data, Class<T> type) Upcasts and deserializes the givenDataobject to an object of type T.<I extends SerializedObject<byte[]>>
Stream<DeserializingObject<byte[], I>> deserialize(Stream<I> dataStream, UnknownTypeStrategy unknownTypeStrategy) Upcasts and deserializes a stream of serialized objects.default DeserializingMessagedeserializeMessage(SerializedMessage message, MessageType messageType) Deserializes a singleSerializedMessageinto aDeserializingMessage.default Stream<DeserializingMessage> deserializeMessages(Stream<SerializedMessage> dataStream, MessageType messageType) Deserializes a stream ofSerializedMessageintoDeserializingMessageinstances with the specifiedMessageType.default Stream<DeserializingMessage> deserializeMessages(Stream<SerializedMessage> dataStream, MessageType messageType, UnknownTypeStrategy unknownTypeStrategy) Deserializes a stream ofSerializedMessageintoDeserializingMessageinstances with the specifiedMessageType.default Stream<DeserializingMessage> deserializeMessages(Stream<SerializedMessage> dataStream, MessageType messageType, String topic) Deserializes a stream ofSerializedMessageintoDeserializingMessageinstances with the specifiedMessageType.default Stream<DeserializingMessage> deserializeMessages(Stream<SerializedMessage> dataStream, MessageType messageType, String topic, UnknownTypeStrategy unknownTypeStrategy) Deserializes a stream ofSerializedMessageintoDeserializingMessageinstances with the specifiedMessageType.Downcasts aDataobject to the specified revision level.Downcasts the given object to a previous revision.default RegistrationregisterCasters(Object... casterCandidates) Registers upcasters and downcasters in one step.registerDowncasters(Object... casterCandidates) Registers one or more downcaster candidates.registerTypeCaster(String oldType, String newType) Registers a mapping from an old type identifier to a new one.registerUpcasters(Object... casterCandidates) Registers one or more upcaster candidates.default Data<byte[]> Serializes the given object to aDatawrapper using the default format.Data<byte[]> Serializes the given object into aDatawrapper using the specified format.upcastType(String type) Returns the upcasted type name for a legacy type identifier.Methods inherited from interface ContentFilter
filterContent
-
Method Details
-
serialize
Serializes the given object to aDatawrapper using the default format.- Parameters:
object- the object to serialize- Returns:
- the serialized object wrapped in
Data - Throws:
SerializationException- if serialization fails
-
serialize
Serializes the given object into aDatawrapper using the specified format.- Parameters:
object- the object to serializeformat- the desired serialization format (e.g. \"json\"); may benull- Returns:
- serialized object as
Data - Throws:
SerializationException- if serialization fails
-
deserialize
Upcasts and deserializes the givenDataobject to an object of type T. If the input data cannot be deserialized to a single result (due to upcasting) aDeserializationExceptionis thrown.- Type Parameters:
T- Type of object to deserialize to- Parameters:
data- Data to deserialize- Returns:
- Object resulting from the deserialization
- Throws:
DeserializationException- if deserialization fails
-
deserialize
Upcasts and deserializes the givenDataobject to an object of type T. If the input data cannot be deserialized to a single result (due to upcasting) aDeserializationExceptionis thrown.- Type Parameters:
T- Type of object to deserialize to- Parameters:
data- Data to deserialize- Returns:
- Object resulting from the deserialization
- Throws:
DeserializationException- if deserialization fails
-
deserialize
<I extends SerializedObject<byte[]>> Stream<DeserializingObject<byte[],I>> deserialize(Stream<I> dataStream, UnknownTypeStrategy unknownTypeStrategy) Upcasts and deserializes a stream of serialized objects. Each result in the output stream contains both a provider for the deserialized object and the serialized object after upcasting that is used as the source of the deserialized object.Deserialization is performed lazily. This means that actual conversion for a given result in the output stream only happens if
DeserializingObject.getPayload()is invoked on the result. This has the advantage that a caller can inspect what type will be returned viabefore deciding to go through with the deserialization.invalid reference
DeserializingObject#getSerializedObject()You can specify whether deserialization of a result in the output stream should fail with a
DeserializationExceptionif a type is unknown (not a class). It is up to the implementation to determine what should happen if a type is unknown but thefailOnUnknownTypeflag is false.- Type Parameters:
I- the type of the serialized object- Parameters:
dataStream- data input stream to deserializeunknownTypeStrategy- value that determines what to do when encountering unknown types- Returns:
- a stream containing deserialization results
-
deserializeMessages
default Stream<DeserializingMessage> deserializeMessages(Stream<SerializedMessage> dataStream, MessageType messageType) Deserializes a stream ofSerializedMessageintoDeserializingMessageinstances with the specifiedMessageType.- Parameters:
dataStream- the stream of messagesmessageType- the type of message (COMMAND, EVENT, etc.)- Returns:
- stream of deserialized messages
-
deserializeMessages
default Stream<DeserializingMessage> deserializeMessages(Stream<SerializedMessage> dataStream, MessageType messageType, String topic) Deserializes a stream ofSerializedMessageintoDeserializingMessageinstances with the specifiedMessageType.- Parameters:
dataStream- the stream of messagesmessageType- the type of message (COMMAND, EVENT, etc.)topic- the topic of the message if the type is CUSTOM or DOCUMENT, otherwisenull- Returns:
- stream of deserialized messages
-
deserializeMessages
default Stream<DeserializingMessage> deserializeMessages(Stream<SerializedMessage> dataStream, MessageType messageType, UnknownTypeStrategy unknownTypeStrategy) Deserializes a stream ofSerializedMessageintoDeserializingMessageinstances with the specifiedMessageType.- Parameters:
dataStream- the stream of messagesmessageType- the type of message (COMMAND, EVENT, etc.)unknownTypeStrategy- value that determines what to do when encountering unknown types- Returns:
- stream of deserialized messages
-
deserializeMessages
default Stream<DeserializingMessage> deserializeMessages(Stream<SerializedMessage> dataStream, MessageType messageType, String topic, UnknownTypeStrategy unknownTypeStrategy) Deserializes a stream ofSerializedMessageintoDeserializingMessageinstances with the specifiedMessageType.- Parameters:
dataStream- the stream of messagesmessageType- the type of message (COMMAND, EVENT, etc.)topic- the topic of the message if the type is CUSTOM or DOCUMENT, otherwisenullunknownTypeStrategy- value that determines what to do when encountering unknown types- Returns:
- stream of deserialized messages
-
deserializeMessage
Deserializes a singleSerializedMessageinto aDeserializingMessage. If the input data cannot be deserialized to a single result (due to upcasting) aDeserializationExceptionis thrown.- Parameters:
message- the message to deserializemessageType- the message type- Returns:
- the deserialized message
-
convert
-
clone
Creates a deep copy of the given object using serialization.- Type Parameters:
V- the type of the value- Parameters:
value- the object to clone- Returns:
- a deep copy
-
registerUpcasters
Registers one or more upcaster candidates.- Parameters:
casterCandidates- beans with upcasting logic- Returns:
- a registration handle
-
registerDowncasters
Registers one or more downcaster candidates.- Parameters:
casterCandidates- beans with downcasting logic- Returns:
- a registration handle
-
registerCasters
Registers upcasters and downcasters in one step.- Parameters:
casterCandidates- beans with casting logic- Returns:
- a merged registration handle
-
registerTypeCaster
Registers a mapping from an old type identifier to a new one.- Parameters:
oldType- the legacy type namenewType- the canonical or updated type name- Returns:
- a registration handle
-
upcastType
-
downcast
-
downcast
-