Interface Serializer
-
- All Known Implementing Classes:
AbstractSerializer,JacksonSerializer
public interface SerializerMechanism to convert objects to a byte array and vice versa.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default <T> Tdeserialize(Data<byte[]> data)Upcasts and deserializes the givenDataobject to an object of type T.<I extends SerializedObject<byte[],I>>
Stream<DeserializingObject<byte[],I>>deserialize(Stream<I> dataStream, boolean failOnUnknownType)Upcasts and deserializes a stream of serialized objects.default Stream<DeserializingMessage>deserializeMessages(Stream<SerializedMessage> dataStream, boolean failOnUnknownType, MessageType messageType)Data<byte[]>serialize(Object object)Serializes an object to aDataobject containing a byte array.
-
-
-
Method Detail
-
serialize
Data<byte[]> serialize(Object object)
Serializes an object to aDataobject containing a byte array.- Parameters:
object- The instance to serialize- Returns:
- Data object containing byte array representation of the object
- Throws:
SerializationException- if serialization fails
-
deserialize
default <T> T deserialize(Data<byte[]> data)
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) aSerializationExceptionis thrown.- Type Parameters:
T- Type of object to deserialize to- Parameters:
data- Data to deserialize- Returns:
- Object resulting from the deserialization
- Throws:
SerializationException- if deserialization fails
-
deserialize
<I extends SerializedObject<byte[],I>> Stream<DeserializingObject<byte[],I>> deserialize(Stream<I> dataStream, boolean failOnUnknownType)
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 viaDeserializingObject.getSerializedObject()before deciding to go through with the deserialization.You can specify whether deserialization of a result in the output stream should fail with a
SerializationExceptionif 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 deserializefailOnUnknownType- flag that determines whether deserialization of an unknown type should give an exception- Returns:
- a stream containing deserialization results
-
deserializeMessages
default Stream<DeserializingMessage> deserializeMessages(Stream<SerializedMessage> dataStream, boolean failOnUnknownType, MessageType messageType)
-
-