Class VersionFieldSerializer<T>
java.lang.Object
com.esotericsoftware.kryo.Serializer<T>
com.esotericsoftware.kryo.serializers.FieldSerializer<T, FieldSerializerConfig>
com.esotericsoftware.kryo.serializers.VersionFieldSerializer<T>
- All Implemented Interfaces:
Comparator<FieldSerializer.CachedField>
Serializes objects using direct field assignment, with versioning backward compatibility. Allows fields to have a
@Since(int) annotation to indicate the version they were added. For a particular field, the value in
@Since should never change once created. This is less flexible than FieldSerializer, which can handle most classes
without needing annotations, but it provides backward compatibility. This means that new fields can be added, but removing,
renaming or changing the type of any field will invalidate previous serialized bytes. VersionFieldSerializer has very little
overhead (a single additional varint) compared to FieldSerializer. Forward compatibility is not supported.- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic @interfaceIncremental modification of serialized objects must addVersionFieldSerializer.Sincefor new fields.Nested classes/interfaces inherited from class FieldSerializer
FieldSerializer.Bind, FieldSerializer.CachedField<X>, FieldSerializer.CachedFieldFactory, FieldSerializer.CachedFieldNameStrategy, FieldSerializer.Optional -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanprivate int[]private intFields inherited from class FieldSerializer
access, asmFieldFactory, componentType, config, kryo, objectFieldFactory, removedFields, type, typeParameters -
Constructor Summary
ConstructorsConstructorDescriptionVersionFieldSerializer(Kryo kryo, Class type) VersionFieldSerializer(Kryo kryo, Class type, boolean compatible) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidReads bytes and returns a new object of the specified concrete type.voidRemoves a field so that it won't be serialized.voidremoveField(String fieldName) Removes a field so that it won't be serialized.voidThis method can be called for different fields having the same type.Methods inherited from class FieldSerializer
compare, copy, create, createCopy, getCachedFieldName, getConfig, getCopyTransient, getField, getFields, getGenerics, getGenericsScope, getKryo, getSerializeTransient, getTransientFields, getType, newCachedField, newMatchingCachedField, rebuildCachedFields, rebuildCachedFields, setCopyTransient, setFieldsAsAccessible, setFieldsCanBeNull, setFixedFieldTypes, setGenerics, setIgnoreSyntheticFields, setOptimizedGenerics, setSerializeTransientMethods inherited from class Serializer
getAcceptsNull, isImmutable, setAcceptsNull, setImmutableMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Field Details
-
typeVersion
private int typeVersion -
fieldVersion
private int[] fieldVersion -
compatible
private boolean compatible
-
-
Constructor Details
-
VersionFieldSerializer
-
VersionFieldSerializer
-
-
Method Details
-
initializeCachedFields
protected void initializeCachedFields()- Overrides:
initializeCachedFieldsin classFieldSerializer<T, FieldSerializerConfig>
-
removeField
Description copied from class:FieldSerializerRemoves a field so that it won't be serialized.- Overrides:
removeFieldin classFieldSerializer<T, FieldSerializerConfig>
-
removeField
Description copied from class:FieldSerializerRemoves a field so that it won't be serialized.- Overrides:
removeFieldin classFieldSerializer<T, FieldSerializerConfig>
-
write
Description copied from class:FieldSerializerThis method can be called for different fields having the same type. Even though the raw type is the same, if the type is generic, it could happen that different concrete classes are used to instantiate it. Therefore, in case of different instantiation parameters, the fields analysis should be repeated. TODO: Cache serializer instances generated for a given set of generic parameters. Reuse it later instead of recomputing every time.- Overrides:
writein classFieldSerializer<T, FieldSerializerConfig>- Parameters:
object- May be null ifSerializer.getAcceptsNull()is true.
-
read
Description copied from class:SerializerReads bytes and returns a new object of the specified concrete 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 usesKryoto read a child object may need to be reentrant.This method should not be called directly, instead this serializer can be passed to
Kryoread methods that accept a serialier.- Overrides:
readin classFieldSerializer<T, FieldSerializerConfig>- Returns:
- May be null if
Serializer.getAcceptsNull()is true.
-