public class CompatibleFieldSerializer<T> extends FieldSerializer<T>
FieldSerializer
, it can serialize most classes without needing annotations. The forward and backward compatibility
comes at a cost: the first time the class is encountered in the serialized bytes, a simple schema is written containing the
field name strings. Also, during serialization and deserialization buffers are allocated to perform chunked encoding. This is
what enables CompatibleFieldSerializer to skip bytes for fields it does not know about.
Removing fields when references
are enabled can cause compatibility issues. See
here.
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.Bind, FieldSerializer.CachedField<X>, FieldSerializer.CachedFieldFactory, FieldSerializer.CachedFieldNameStrategy, FieldSerializer.Optional
config, removedFields
Constructor and Description |
---|
CompatibleFieldSerializer(Kryo kryo,
Class type) |
Modifier and Type | Method and Description |
---|---|
T |
read(Kryo kryo,
Input input,
Class<T> type)
Reads bytes and returns a new object of the specified concrete type.
|
void |
write(Kryo kryo,
Output output,
T object)
This method can be called for different fields having the same type.
|
compare, copy, create, createCopy, getCachedFieldName, getCopyTransient, getField, getFields, getGenerics, getKryo, getSerializeTransient, getTransientFields, getType, getUseAsmEnabled, getUseMemRegions, initializeCachedFields, rebuildCachedFields, rebuildCachedFields, removeField, removeField, setCopyTransient, setFieldsAsAccessible, setFieldsCanBeNull, setFixedFieldTypes, setGenerics, setIgnoreSyntheticFields, setOptimizedGenerics, setSerializeTransient, setUseAsm
getAcceptsNull, isImmutable, setAcceptsNull, setImmutable
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
comparing, comparing, comparingDouble, comparingInt, comparingLong, equals, naturalOrder, nullsFirst, nullsLast, reversed, reverseOrder, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
public void write(Kryo kryo, Output output, T object)
FieldSerializer
write
in class FieldSerializer<T>
object
- May be null if Serializer.getAcceptsNull()
is true.public T read(Kryo kryo, Input input, 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.Copyright © 2018. All rights reserved.