public abstract class Serializer<T>
extends java.lang.Object
Constructor and Description |
---|
Serializer() |
Serializer(boolean acceptsNull) |
Serializer(boolean acceptsNull,
boolean immutable) |
Modifier and Type | Method and 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,
java.lang.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,
java.lang.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.
|
public Serializer()
public Serializer(boolean acceptsNull)
setAcceptsNull(boolean)
public Serializer(boolean acceptsNull, boolean immutable)
setAcceptsNull(boolean)
,
setImmutable(boolean)
public abstract void write(Kryo kryo, Output output, T object)
This method should not be called directly, instead this serializer can be passed to Kryo
write methods that accept a
serialier.
object
- May be null if getAcceptsNull()
is true.public abstract T read(Kryo kryo, Input input, java.lang.Class<T> 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.
getAcceptsNull()
is true.public boolean getAcceptsNull()
public void setAcceptsNull(boolean acceptsNull)
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.
public boolean isImmutable()
public void setImmutable(boolean immutable)
copy(Kryo, Object)
to
return the original object.public void setGenerics(Kryo kryo, java.lang.Class[] generics)
generics
- Some (but never all) elements may be null if there is no generic type information at that index.public T copy(Kryo kryo, T original)
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.