Package se.l4.commons.serialization
Interface Serializer<T>
- Type Parameters:
T-
- All Superinterfaces:
SerializerOrResolver<T>
- All Known Implementing Classes:
ArraySerializer,BooleanArraySerializer,BooleanSerializer,ByteArraySerializer,ByteSerializer,CharacterSerializer,CharArraySerializer,CompactDynamicSerializer,DelayedSerializer,DoubleArraySerializer,DoubleSerializer,DynamicSerializer,EnumSerializer,FloatArraySerializer,FloatSerializer,IntArraySerializer,IntSerializer,ListSerializer,LongArraySerializer,LongSerializer,MapAsObjectSerializer,OptionalSerializer,ReflectionNonStreamingSerializer,ReflectionOnlySingleFactorySerializer,ReflectionStreamingSerializer,SetSerializer,ShortArraySerializer,ShortSerializer,SimpleTypeSerializer,StringSerializer,UuidSerializer
public interface Serializer<T> extends SerializerOrResolver<T>
Serializer for a specific class. A serializer is used to read and write
objects and is usually bound to a specific class. Serializers are retrieved
via a
SerializerCollection.- Author:
- Andreas Holstenson
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfaceSerializer.NullHandlingMarker interface used when a serializer wants to handle an incomingnullvalue. -
Method Summary
Modifier and Type Method Description default Function<byte[],T>fromBytes()Create a new function that turns byte arrays into objects.default TfromBytes(byte[] data)Read an instance from the given byte data.default SerializerFormatDefinitiongetFormatDefinition()Get the definition that describes what this serializer can read and write.Tread(StreamingInput in)Read an object from the specified stream.default Function<T,byte[]>toBytes()Create a new function that turns objects into byte arrays.default byte[]toBytes(T instance)Turn an object into a byte array.voidwrite(T object, String name, StreamingOutput out)Write and object to the specified stream.
-
Method Details
-
read
Read an object from the specified stream.- Parameters:
in-- Returns:
- Throws:
IOException
-
write
void write(@UnknownNullness T object, @NonNull String name, @NonNull StreamingOutput out) throws IOExceptionWrite and object to the specified stream.- Parameters:
object- object to write, if the serializer implementsSerializer.NullHandlingthis may benull, if not the serializer can assume it is notnullname- the name the object should have, should be passed along to the outputout- the stream to use for writing- Throws:
IOException- if unable to write the object
-
getFormatDefinition
Get the definition that describes what this serializer can read and write.- Returns:
-
toBytes
Turn an object into a byte array.- Parameters:
instance-- Returns:
-
toBytes
Create a new function that turns objects into byte arrays.- Returns:
-
fromBytes
Read an instance from the given byte data.- Parameters:
data-- Returns:
-
fromBytes
Create a new function that turns byte arrays into objects.- Returns:
-