public class VersionFieldSerializer<T> extends FieldSerializer<T>
When a field is added, it must have the VersionFieldSerializer.Since
annotation to indicate the version it was added in order to be compatible
with previously serialized bytes. The annotation value must never change.
Compared to FieldSerializer
, VersionFieldSerializer writes a single additional varint and requires annotations for
added fields, but provides backward compatibility so fields can be added. TaggedFieldSerializer
provides more
flexibility for classes to evolve in exchange for a slightly larger serialized size.
Modifier and Type | Class and Description |
---|---|
static interface |
VersionFieldSerializer.Since
Incremental modification of serialized objects must add
VersionFieldSerializer.Since for new fields. |
static class |
VersionFieldSerializer.VersionFieldSerializerConfig
Configuration for VersionFieldSerializer instances.
|
FieldSerializer.Bind, FieldSerializer.CachedField, FieldSerializer.FieldSerializerConfig, FieldSerializer.NotNull, FieldSerializer.Optional
Constructor and Description |
---|
VersionFieldSerializer(Kryo kryo,
java.lang.Class type) |
VersionFieldSerializer(Kryo kryo,
java.lang.Class type,
VersionFieldSerializer.VersionFieldSerializerConfig config) |
Modifier and Type | Method and Description |
---|---|
VersionFieldSerializer.VersionFieldSerializerConfig |
getVersionFieldSerializerConfig() |
protected void |
initializeCachedFields()
Called when
FieldSerializer.getFields() and FieldSerializer.getCopyFields() have been repopulated. |
T |
read(Kryo kryo,
Input input,
java.lang.Class<? extends T> type)
Reads bytes and returns a new object of the specified concrete type.
|
void |
removeField(FieldSerializer.CachedField field)
Removes a field so that it won't be serialized.
|
void |
removeField(java.lang.String fieldName)
Removes a field so that it won't be serialized.
|
void |
write(Kryo kryo,
Output output,
T object)
Writes the bytes for the object to the output.
|
copy, create, createCopy, getCopyFields, getField, getFields, getFieldSerializerConfig, getKryo, getType, log, popTypeVariables, pushTypeVariables, updateFields
getAcceptsNull, isImmutable, setAcceptsNull, setImmutable
public VersionFieldSerializer(Kryo kryo, java.lang.Class type)
public VersionFieldSerializer(Kryo kryo, java.lang.Class type, VersionFieldSerializer.VersionFieldSerializerConfig config)
protected void initializeCachedFields()
FieldSerializer
FieldSerializer.getFields()
and FieldSerializer.getCopyFields()
have been repopulated. Subclasses can override this method to
configure or remove cached fields.initializeCachedFields
in class FieldSerializer<T>
public void removeField(java.lang.String fieldName)
FieldSerializer
removeField
in class FieldSerializer<T>
public void removeField(FieldSerializer.CachedField field)
FieldSerializer
removeField
in class FieldSerializer<T>
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<? extends 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.public VersionFieldSerializer.VersionFieldSerializerConfig getVersionFieldSerializerConfig()
Copyright © 2019. All Rights Reserved.