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 interface  Serializer.NullHandling
    Marker interface used when a serializer wants to handle an incoming null value.
  • Method Summary

    Modifier and Type Method Description
    default Function<byte[],​T> fromBytes()
    Create a new function that turns byte arrays into objects.
    default T fromBytes​(byte[] data)
    Read an instance from the given byte data.
    default SerializerFormatDefinition getFormatDefinition()
    Get the definition that describes what this serializer can read and write.
    T read​(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.
    void write​(T object, String name, StreamingOutput out)
    Write and object to the specified stream.
  • Method Details

    • read

      @Nullable T read​(@NonNull StreamingInput in) throws IOException
      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 IOException
      Write and object to the specified stream.
      Parameters:
      object - object to write, if the serializer implements Serializer.NullHandling this may be null, if not the serializer can assume it is not null
      name - the name the object should have, should be passed along to the output
      out - the stream to use for writing
      Throws:
      IOException - if unable to write the object
    • getFormatDefinition

      @NonNull default SerializerFormatDefinition getFormatDefinition()
      Get the definition that describes what this serializer can read and write.
      Returns:
    • toBytes

      @Nullable default byte[] toBytes​(@Nullable T instance)
      Turn an object into a byte array.
      Parameters:
      instance -
      Returns:
    • toBytes

      @NonNull default Function<T,​byte[]> toBytes()
      Create a new function that turns objects into byte arrays.
      Returns:
    • fromBytes

      @Nullable default T fromBytes​(@Nullable byte[] data)
      Read an instance from the given byte data.
      Parameters:
      data -
      Returns:
    • fromBytes

      @NonNull default Function<byte[],​T> fromBytes()
      Create a new function that turns byte arrays into objects.
      Returns: