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 Flux Capacitor’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> V
Creates a deep copy of the given object using serialization.<V> V
Converts a given object to another type using the serializer's object mapping rules.default <T> T
deserialize
(SerializedObject<byte[]> data) Upcasts and deserializes the givenData
object to an object of type T.default <T> T
deserialize
(SerializedObject<byte[]> data, Class<T> type) Upcasts and deserializes the givenData
object 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 DeserializingMessage
deserializeMessage
(SerializedMessage message, MessageType messageType) Deserializes a singleSerializedMessage
into aDeserializingMessage
.default Stream
<DeserializingMessage> deserializeMessages
(Stream<SerializedMessage> dataStream, MessageType messageType) Deserializes a stream ofSerializedMessage
intoDeserializingMessage
instances with the specifiedMessageType
.default Stream
<DeserializingMessage> deserializeMessages
(Stream<SerializedMessage> dataStream, MessageType messageType, UnknownTypeStrategy unknownTypeStrategy) Deserializes a stream ofSerializedMessage
intoDeserializingMessage
instances with the specifiedMessageType
.default Stream
<DeserializingMessage> deserializeMessages
(Stream<SerializedMessage> dataStream, MessageType messageType, String topic) Deserializes a stream ofSerializedMessage
intoDeserializingMessage
instances with the specifiedMessageType
.default Stream
<DeserializingMessage> deserializeMessages
(Stream<SerializedMessage> dataStream, MessageType messageType, String topic, UnknownTypeStrategy unknownTypeStrategy) Deserializes a stream ofSerializedMessage
intoDeserializingMessage
instances with the specifiedMessageType
.Downcasts aData
object to the specified revision level.Downcasts the given object to a previous revision.default Registration
registerCasters
(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 aData
wrapper using the default format.Data
<byte[]> Serializes the given object into aData
wrapper using the specified format.upcastType
(String type) Returns the upcasted type name for a legacy type identifier.Methods inherited from interface io.fluxcapacitor.javaclient.common.serialization.ContentFilter
filterContent
-
Method Details
-
serialize
Serializes the given object to aData
wrapper 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 aData
wrapper 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 givenData
object to an object of type T. If the input data cannot be deserialized to a single result (due to upcasting) aDeserializationException
is 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 givenData
object to an object of type T. If the input data cannot be deserialized to a single result (due to upcasting) aDeserializationException
is 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 viainvalid reference
DeserializingObject#getSerializedObject()
You can specify whether deserialization of a result in the output stream should fail with a
DeserializationException
if a type is unknown (not a class). It is up to the implementation to determine what should happen if a type is unknown but thefailOnUnknownType
flag 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 ofSerializedMessage
intoDeserializingMessage
instances 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 ofSerializedMessage
intoDeserializingMessage
instances 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 ofSerializedMessage
intoDeserializingMessage
instances 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 ofSerializedMessage
intoDeserializingMessage
instances 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
unknownTypeStrategy
- value that determines what to do when encountering unknown types- Returns:
- stream of deserialized messages
-
deserializeMessage
Deserializes a singleSerializedMessage
into aDeserializingMessage
. If the input data cannot be deserialized to a single result (due to upcasting) aDeserializationException
is thrown.- Parameters:
message
- the message to deserializemessageType
- the message type- Returns:
- the deserialized message
-
convert
Converts a given object to another type using the serializer's object mapping rules.- Type Parameters:
V
- the result type- Parameters:
value
- the input valuetype
- the target type- Returns:
- the converted value
-
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
Returns the upcasted type name for a legacy type identifier.- Parameters:
type
- the original type- Returns:
- the remapped (or unchanged) type name
-
downcast
Downcasts the given object to a previous revision.- Parameters:
object
- the object to downcastdesiredRevision
- the target revision- Returns:
- a revisioned form of the object
-
downcast
Downcasts aData
object to the specified revision level.- Parameters:
data
- the serialized datadesiredRevision
- the target revision number- Returns:
- a transformed object matching the older revision
-