Interface Serializer
- All Known Implementing Classes:
AbstractSerializer,JacksonSerializer
public interface Serializer
Mechanism to convert objects to a byte array and vice versa.
-
Method Summary
Modifier and TypeMethodDescription<V> V<V> Vdefault <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, MessageType messageType) default Stream<DeserializingMessage>deserializeMessages(Stream<SerializedMessage> dataStream, MessageType messageType, boolean failOnUnknownType) registerTypeCaster(String oldType, String newType) default Data<byte[]>Serializes an object to aDataobject containing a byte array.Data<byte[]>Serializes an object using the given desiredformatto aDataobject containing a byte array.upcastType(String type)
-
Method Details
-
serialize
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
-
serialize
Serializes an object using the given desiredformatto aDataobject containing a byte array. If format isnullthe default format of this serializer may be used.- Parameters:
object- The instance to serialize- Returns:
- Data object containing byte array representation of the object
- 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) 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, MessageType messageType) -
deserializeMessages
default Stream<DeserializingMessage> deserializeMessages(Stream<SerializedMessage> dataStream, MessageType messageType, boolean failOnUnknownType) -
convert
-
clone
-
registerTypeCaster
-
upcastType
-