Class Serializer<T>

java.lang.Object
com.esotericsoftware.kryo.Serializer<T>
Direct Known Subclasses:
BeanSerializer, BlowfishSerializer, ClosureSerializer, CollectionSerializer, DefaultArraySerializers.BooleanArraySerializer, DefaultArraySerializers.ByteArraySerializer, DefaultArraySerializers.CharArraySerializer, DefaultArraySerializers.DoubleArraySerializer, DefaultArraySerializers.FloatArraySerializer, DefaultArraySerializers.IntArraySerializer, DefaultArraySerializers.LongArraySerializer, DefaultArraySerializers.ObjectArraySerializer, DefaultArraySerializers.ShortArraySerializer, DefaultArraySerializers.StringArraySerializer, DefaultSerializers.BigDecimalSerializer, DefaultSerializers.BigIntegerSerializer, DefaultSerializers.BooleanSerializer, DefaultSerializers.ByteSerializer, DefaultSerializers.CalendarSerializer, DefaultSerializers.CharSerializer, DefaultSerializers.CharsetSerializer, DefaultSerializers.ClassSerializer, DefaultSerializers.CollectionsEmptyListSerializer, DefaultSerializers.CollectionsEmptyMapSerializer, DefaultSerializers.CollectionsEmptySetSerializer, DefaultSerializers.CollectionsSingletonListSerializer, DefaultSerializers.CollectionsSingletonMapSerializer, DefaultSerializers.CollectionsSingletonSetSerializer, DefaultSerializers.CurrencySerializer, DefaultSerializers.DateSerializer, DefaultSerializers.DoubleSerializer, DefaultSerializers.EnumSerializer, DefaultSerializers.EnumSetSerializer, DefaultSerializers.FloatSerializer, DefaultSerializers.IntSerializer, DefaultSerializers.KryoSerializableSerializer, DefaultSerializers.LocaleSerializer, DefaultSerializers.LongSerializer, DefaultSerializers.ShortSerializer, DefaultSerializers.StringBufferSerializer, DefaultSerializers.StringBuilderSerializer, DefaultSerializers.StringSerializer, DefaultSerializers.TimeZoneSerializer, DefaultSerializers.URLSerializer, DefaultSerializers.VoidSerializer, DeflateSerializer, EnumNameSerializer, ExternalizableSerializer, FieldSerializer, JavaSerializer, MapSerializer, OptionalSerializers.OptionalDoubleSerializer, OptionalSerializers.OptionalIntSerializer, OptionalSerializers.OptionalLongSerializer, OptionalSerializers.OptionalSerializer, TimeSerializers.DurationSerializer, TimeSerializers.InstantSerializer, TimeSerializers.LocalDateSerializer, TimeSerializers.LocalDateTimeSerializer, TimeSerializers.LocalTimeSerializer, TimeSerializers.MonthDaySerializer, TimeSerializers.OffsetDateTimeSerializer, TimeSerializers.OffsetTimeSerializer, TimeSerializers.PeriodSerializer, TimeSerializers.YearMonthSerializer, TimeSerializers.YearSerializer, TimeSerializers.ZonedDateTimeSerializer, TimeSerializers.ZoneIdSerializer, TimeSerializers.ZoneOffsetSerializer

public abstract class Serializer<T> extends Object
Reads and writes objects to and from bytes.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private boolean
     
    private boolean
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
    Serializer(boolean acceptsNull)
     
    Serializer(boolean acceptsNull, boolean immutable)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    copy(Kryo kryo, T original)
    Returns a copy of the specified object.
    boolean
     
    boolean
     
    abstract T
    read(Kryo kryo, Input input, Class<T> type)
    Reads bytes and returns a new object of the specified concrete type.
    void
    setAcceptsNull(boolean acceptsNull)
    If true, this serializer will handle writing and reading null values.
    void
    setGenerics(Kryo kryo, Class[] generics)
    Sets the generic types of the field or method this serializer will be used for on the next call to read or write.
    void
    setImmutable(boolean immutable)
    If true, the type this serializer will be used for is considered immutable.
    abstract void
    write(Kryo kryo, Output output, T object)
    Writes the bytes for the object to the output.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • acceptsNull

      private boolean acceptsNull
    • immutable

      private boolean immutable
  • Constructor Details

  • Method Details

    • write

      public abstract void write(Kryo kryo, Output output, T object)
      Writes the bytes for the object to the output.

      This method should not be called directly, instead this serializer can be passed to Kryo write methods that accept a serialier.

      Parameters:
      object - May be null if getAcceptsNull() is true.
    • read

      public abstract T read(Kryo kryo, Input input, Class<T> type)
      Reads bytes and returns a new object of the specified concrete type.

      Before Kryo can be used to read child objects, Kryo.reference(Object) must be called with the parent object to ensure it can be referenced by the child objects. Any serializer that uses Kryo to read a child object may need to be reentrant.

      This method should not be called directly, instead this serializer can be passed to Kryo read methods that accept a serialier.

      Returns:
      May be null if getAcceptsNull() is true.
    • getAcceptsNull

      public boolean getAcceptsNull()
    • setAcceptsNull

      public void setAcceptsNull(boolean acceptsNull)
      If true, this serializer will handle writing and reading null values. If false, the Kryo framework handles null values and the serializer will never receive null.

      This can be set to true on a serializer that does not accept nulls if it is known that the serializer will never encounter null. Doing this will prevent the framework from writing a byte to denote null.

    • isImmutable

      public boolean isImmutable()
    • setImmutable

      public void setImmutable(boolean immutable)
      If true, the type this serializer will be used for is considered immutable. This causes copy(Kryo, Object) to return the original object.
    • setGenerics

      public void setGenerics(Kryo kryo, Class[] generics)
      Sets the generic types of the field or method this serializer will be used for on the next call to read or write. Subsequent calls to read and write must not use this generic type information. The default implementation does nothing. Subclasses may use the information provided to this method for more efficient serialization, eg to use the same type for all items in a list.
      Parameters:
      generics - Some (but never all) elements may be null if there is no generic type information at that index.
    • copy

      public T copy(Kryo kryo, T original)
      Returns a copy of the specified object. The default implementation returns the original if isImmutable() is true, else throws KryoException. Subclasses should override this method if needed to support Kryo.copy(Object).

      Before Kryo can be used to copy child objects, Kryo.reference(Object) must be called with the copy to ensure it can be referenced by the child objects. Any serializer that uses Kryo to copy a child object may need to be reentrant.

      This method should not be called directly, instead this serializer can be passed to Kryo copy methods that accept a serialier.