Class TaggedFieldSerializer<T>

All Implemented Interfaces:
Comparator<FieldSerializer.CachedField>

public class TaggedFieldSerializer<T> extends FieldSerializer<T,TaggedFieldSerializerConfig>
Serializes objects using direct field assignment for fields that have a @Tag(int) annotation. This provides backward compatibility so new fields can be added. TaggedFieldSerializer has two advantages over VersionFieldSerializer : 1) fields can be renamed and 2) fields marked with the @Deprecated annotation will be ignored when reading old bytes and won't be written to new bytes. Deprecation effectively removes the field from serialization, though the field and @Tag annotation must remain in the class. Deprecated fields can optionally be made private and/or renamed so they don't clutter the class (eg, ignored, ignored2). For these reasons, TaggedFieldSerializer generally provides more flexibility for classes to evolve. The downside is that it has a small amount of additional overhead compared to VersionFieldSerializer (an additional varint per field).

Forward compatibility is optionally supported by enabling TaggedFieldSerializerConfig.setSkipUnknownTags(boolean), which allows it to skip reading unknown tagged fields, which are presumably new fields added in future versions of an application. The data is only forward compatible if the newly added fields are tagged with TaggedFieldSerializer.Tag.annexed() set true, which comes with the cost of chunked encoding. When annexed fields are encountered during the read or write process of an object, a buffer is allocated to perform the chunked encoding.

Tag values must be entirely unique, even among a class and its superclass(es). An IllegalArgumentException will be thrown by Kryo.register(Class) (and its overloads) if duplicate Tag values are encountered.

See Also: