Class FieldSerializer<T>
- All Implemented Interfaces:
Comparator<FieldSerializer.CachedField>
- Direct Known Subclasses:
CompatibleFieldSerializer,TaggedFieldSerializer
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassControls how a field will be serialized.static @interfaceIndicates a field should be ignored when its declaring class is registered unless thecontexthas a value set for the specified key. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintReturns a copy of the specified object.protected TUsed byread(Kryo, Input, Class)to create the new object.protected TcreateCopy(Kryo kryo, T original) Used bycopy(Kryo, Object)to create the new object.Allows specific fields to be optimized.getType()protected voidReads bytes and returns a new object of the specified concrete type.voidremoveField(String fieldName) Removes a field so that it won't be serialized.voidsetFieldsAsAccessible(boolean setFieldsAsAccessible) Controls which fields are serialized.voidsetFieldsCanBeNull(boolean fieldsCanBeNull) Sets the default value forFieldSerializer.CachedField.setCanBeNull(boolean).voidsetFixedFieldTypes(boolean fixedFieldTypes) Sets the default value forFieldSerializer.CachedField.setClass(Class)to the field's declared type.voidsetIgnoreSyntheticFields(boolean ignoreSyntheticFields) Controls if synthetic fields are serialized.voidWrites the bytes for the object to the output.Methods inherited from class com.esotericsoftware.kryo.Serializer
getAcceptsNull, isImmutable, setAcceptsNull, setGenerics, setImmutableMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Constructor Details
-
FieldSerializer
-
-
Method Details
-
initializeCachedFields
protected void initializeCachedFields() -
compare
- Specified by:
comparein interfaceComparator<T>
-
setFieldsCanBeNull
public void setFieldsCanBeNull(boolean fieldsCanBeNull) Sets the default value forFieldSerializer.CachedField.setCanBeNull(boolean). Calling this method resets thecached fields.- Parameters:
fieldsCanBeNull- False if none of the fields are null. Saves 0-1 byte per field. True if it is not known (default).
-
setFieldsAsAccessible
public void setFieldsAsAccessible(boolean setFieldsAsAccessible) Controls which fields are serialized. Calling this method resets thecached fields.- Parameters:
setFieldsAsAccessible- If true, all non-transient fields (inlcuding private fields) will be serialized andset as accessibleif necessary (default). If false, only fields in the public API will be serialized.
-
setIgnoreSyntheticFields
public void setIgnoreSyntheticFields(boolean ignoreSyntheticFields) Controls if synthetic fields are serialized. Default is true. Calling this method resets thecached fields.- Parameters:
ignoreSyntheticFields- If true, only non-synthetic fields will be serialized.
-
setFixedFieldTypes
public void setFixedFieldTypes(boolean fixedFieldTypes) Sets the default value forFieldSerializer.CachedField.setClass(Class)to the field's declared type. This allows FieldSerializer to be more efficient, since it knows field values will not be a subclass of their declared type. Default is false. Calling this method resets thecached fields. -
write
Description copied from class:SerializerWrites the bytes for the object to the output.This method should not be called directly, instead this serializer can be passed to
Kryowrite methods that accept a serialier.- Specified by:
writein classSerializer<T>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.- Specified by:
readin classSerializer<T>- Returns:
- May be null if
Serializer.getAcceptsNull()is true.
-
create
Used byread(Kryo, Input, Class)to create the new object. This can be overridden to customize object creation, eg to call a constructor with arguments. The default implementation usesKryo.newInstance(Class). -
getField
Allows specific fields to be optimized. -
removeField
Removes a field so that it won't be serialized. -
getFields
-
getType
-
createCopy
Used bycopy(Kryo, Object)to create the new object. This can be overridden to customize object creation, eg to call a constructor with arguments. The default implementation usesKryo.newInstance(Class). -
copy
Description copied from class:SerializerReturns a copy of the specified object. The default implementation returns the original ifSerializer.isImmutable()is true, else throwsKryoException. Subclasses should override this method if needed to supportKryo.copy(Object).Before Kryo can be used to copy child objects,
Kryo.reference(Object)must be called with the copy to ensure it can be referenced by the child objects. Any serializer that usesKryoto copy a child object may need to be reentrant.This method should not be called directly, instead this serializer can be passed to
Kryocopy methods that accept a serialier.- Overrides:
copyin classSerializer<T>
-