Class 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
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionSerializer
(boolean acceptsNull) Serializer
(boolean acceptsNull, boolean immutable) -
Method Summary
Modifier and TypeMethodDescriptionReturns a copy of the specified object.boolean
boolean
abstract T
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
Writes the bytes for the object to the output.
-
Field Details
-
acceptsNull
private boolean acceptsNull -
immutable
private boolean immutable
-
-
Constructor Details
-
Serializer
public Serializer() -
Serializer
public Serializer(boolean acceptsNull) - See Also:
-
Serializer
public Serializer(boolean acceptsNull, boolean immutable) - See Also:
-
-
Method Details
-
write
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
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. -
setGenerics
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
Returns a copy of the specified object. The default implementation returns the original ifisImmutable()
is true, else throwsKryoException
. Subclasses should override this method if needed 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. Any 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.
-