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.AtomicBooleanSerializer
,DefaultSerializers.AtomicIntegerSerializer
,DefaultSerializers.AtomicLongSerializer
,DefaultSerializers.AtomicReferenceSerializer
,DefaultSerializers.BitSetSerializer
,DefaultSerializers.CalendarSerializer
,DefaultSerializers.CollectionsSingletonListSerializer
,DefaultSerializers.CollectionsSingletonMapSerializer
,DefaultSerializers.CollectionsSingletonSetSerializer
,DefaultSerializers.DateSerializer
,DefaultSerializers.EnumSetSerializer
,DefaultSerializers.KryoSerializableSerializer
,DefaultSerializers.StringBufferSerializer
,DefaultSerializers.StringBuilderSerializer
,DefaultSerializers.TimestampSerializer
,DeflateSerializer
,ExternalizableSerializer
,FieldSerializer
,ImmutableSerializer
,JavaSerializer
,MapSerializer
,OptionalSerializers.OptionalSerializer
public abstract class Serializer<T> extends Object
Reads and writes objects to and from bytes.- Author:
- Nathan Sweet
-
-
Constructor Summary
Constructors Constructor Description Serializer()
Serializer(boolean acceptsNull)
Serializer(boolean acceptsNull, boolean immutable)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description T
copy(Kryo kryo, T original)
Returns a copy of the specified object.boolean
getAcceptsNull()
boolean
isImmutable()
abstract T
read(Kryo kryo, Input input, Class<? extends 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
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.
-
-
-
Constructor Detail
-
Serializer
public Serializer()
-
Serializer
public Serializer(boolean acceptsNull)
- See Also:
setAcceptsNull(boolean)
-
Serializer
public Serializer(boolean acceptsNull, boolean immutable)
- See Also:
setAcceptsNull(boolean)
,setImmutable(boolean)
-
-
Method Detail
-
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 ifgetAcceptsNull()
is true.
-
read
public abstract T read(Kryo kryo, Input input, Class<? extends 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 usesKryo
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 causescopy(Kryo, Object)
to return the original object.
-
copy
public T copy(Kryo kryo, T original)
Returns a copy of the specified object. The default implementation returns the original ifisImmutable()
is true, else throwsKryoException
. Subclasses can optionall override this method to supportKryo.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. A serializer that usesKryo
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.
-
-