public class CompatibleFieldSerializer<T> extends FieldSerializer<T>
There is additional overhead compared to FieldSerializer
. A header is output the first time an object of a given type
is serialized. The header consists of an int for the number of fields, then a String for each field name. Also, to support
skipping the bytes for a field that no longer exists, for each field value an int is written that is the length of the value in
bytes.
Note that the field data is identified by name. The situation where a super class has a field with the same name as a subclass must be avoided.
FieldSerializer.CachedField<X>, FieldSerializer.Optional
Constructor and Description |
---|
CompatibleFieldSerializer(Kryo kryo,
java.lang.Class type) |
Modifier and Type | Method and Description |
---|---|
T |
read(Kryo kryo,
Input input,
java.lang.Class<T> type)
Reads bytes and returns a new object of the specified concrete type.
|
void |
write(Kryo kryo,
Output output,
T object)
Writes the bytes for the object to the output.
|
compare, copy, getField, getFields, getType, removeField, setFieldsAsAccessible, setFieldsCanBeNull, setFixedFieldTypes, setIgnoreSyntheticFields
getAcceptsNull, isImmutable, setAcceptsNull, setGenerics, setImmutable
public CompatibleFieldSerializer(Kryo kryo, java.lang.Class type)
public void write(Kryo kryo, Output output, T object)
Serializer
This method should not be called directly, instead this serializer can be passed to Kryo
write methods that accept a
serialier.
write
in class FieldSerializer<T>
object
- May be null if Serializer.getAcceptsNull()
is true.public T read(Kryo kryo, Input input, java.lang.Class<T> type)
Serializer
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.
read
in class FieldSerializer<T>
Serializer.getAcceptsNull()
is true.