public class FieldSerializer<T> extends Serializer<T> implements Comparator<FieldSerializer.CachedField>
Serializer
,
Kryo.register(Class, Serializer)
,
VersionFieldSerializer
,
TaggedFieldSerializer
,
CompatibleFieldSerializer
Modifier and Type | Class and Description |
---|---|
static interface |
FieldSerializer.Bind
Used to annotate fields with a specific Kryo serializer.
|
static class |
FieldSerializer.CachedField<X>
Controls how a field will be serialized.
|
static interface |
FieldSerializer.CachedFieldFactory |
static interface |
FieldSerializer.Optional
Indicates a field should be ignored when its declaring class is registered unless the
context has
a value set for the specified key. |
Modifier and Type | Field and Description |
---|---|
protected HashSet<FieldSerializer.CachedField> |
removedFields |
Constructor and Description |
---|
FieldSerializer(Kryo kryo,
Class type) |
FieldSerializer(Kryo kryo,
Class type,
Class[] generics) |
Modifier and Type | Method and Description |
---|---|
int |
compare(FieldSerializer.CachedField o1,
FieldSerializer.CachedField o2) |
T |
copy(Kryo kryo,
T original)
Returns a copy of the specified object.
|
protected T |
create(Kryo kryo,
Input input,
Class<T> type)
Used by
read(Kryo, Input, Class) to create the new object. |
protected T |
createCopy(Kryo kryo,
T original)
Used by
copy(Kryo, Object) to create the new object. |
boolean |
getCopyTransient() |
FieldSerializer.CachedField |
getField(String fieldName)
Allows specific fields to be optimized.
|
FieldSerializer.CachedField[] |
getFields()
Get all fields controlled by this FieldSerializer
|
Class[] |
getGenerics()
Get generic type parameters of the class controlled by this serializer.
|
Generics |
getGenericsScope() |
Kryo |
getKryo() |
Class |
getType() |
boolean |
getUseAsmEnabled() |
boolean |
getUseMemRegions() |
protected void |
initializeCachedFields() |
T |
read(Kryo kryo,
Input input,
Class<T> type)
Reads bytes and returns a new object of the specified concrete type.
|
protected void |
rebuildCachedFields()
Called when the list of cached fields must be rebuilt.
|
protected void |
rebuildCachedFields(boolean minorRebuild)
Rebuilds the list of cached fields.
|
void |
removeField(FieldSerializer.CachedField removeField)
Removes a field so that it won't be serialized.
|
void |
removeField(String fieldName)
Removes a field so that it won't be serialized.
|
void |
setCopyTransient(boolean setCopyTransient) |
void |
setFieldsAsAccessible(boolean setFieldsAsAccessible)
Controls which fields are serialized.
|
void |
setFieldsCanBeNull(boolean fieldsCanBeNull)
Sets the default value for
FieldSerializer.CachedField.setCanBeNull(boolean) . |
void |
setFixedFieldTypes(boolean fixedFieldTypes)
Sets the default value for
FieldSerializer.CachedField.setClass(Class) to the field's declared type. |
void |
setGenerics(Kryo kryo,
Class[] generics)
Sets the generic types of the field or method this serializer will be used for on the next call to read or write.
|
void |
setIgnoreSyntheticFields(boolean ignoreSyntheticFields)
Controls if synthetic fields are serialized.
|
void |
setUseAsm(boolean setUseAsm)
Controls whether ASM should be used.
|
void |
write(Kryo kryo,
Output output,
T object)
This method can be called for different fields having the same type.
|
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
protected HashSet<FieldSerializer.CachedField> removedFields
protected void rebuildCachedFields()
protected void rebuildCachedFields(boolean minorRebuild)
minorRebuild
- if set, processing due to changes in generic type parameters will be optimizedpublic void setGenerics(Kryo kryo, Class[] generics)
Serializer
setGenerics
in class Serializer<T>
generics
- Some (but never all) elements may be null if there is no generic type information at that index.public Class[] getGenerics()
protected void initializeCachedFields()
public int compare(FieldSerializer.CachedField o1, FieldSerializer.CachedField o2)
compare
in interface Comparator<FieldSerializer.CachedField>
public void setFieldsCanBeNull(boolean fieldsCanBeNull)
FieldSerializer.CachedField.setCanBeNull(boolean)
. Calling this method resets the cached fields
.fieldsCanBeNull
- False if none of the fields are null. Saves 0-1 byte per field. True if it is not known (default).public void setFieldsAsAccessible(boolean setFieldsAsAccessible)
cached fields
.setFieldsAsAccessible
- If true, all non-transient fields (inlcuding private fields) will be serialized and
set as accessible
if necessary (default). If false, only fields in the public
API will be serialized.public void setIgnoreSyntheticFields(boolean ignoreSyntheticFields)
cached
fields
.ignoreSyntheticFields
- If true, only non-synthetic fields will be serialized.public void setFixedFieldTypes(boolean fixedFieldTypes)
FieldSerializer.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 the cached fields
.public void setUseAsm(boolean setUseAsm)
cached fields
.setUseAsm
- If true, ASM will be used for fast serialization. If false, Unsafe will be used (default)public void setCopyTransient(boolean setCopyTransient)
public void write(Kryo kryo, Output output, T object)
write
in class Serializer<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 Serializer<T>
Serializer.getAcceptsNull()
is true.protected T create(Kryo kryo, Input input, Class<T> type)
read(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 uses Kryo.newInstance(Class)
.public FieldSerializer.CachedField getField(String fieldName)
public void removeField(String fieldName)
public void removeField(FieldSerializer.CachedField removeField)
public FieldSerializer.CachedField[] getFields()
public Class getType()
public Kryo getKryo()
public boolean getUseAsmEnabled()
public boolean getUseMemRegions()
public boolean getCopyTransient()
protected T createCopy(Kryo kryo, T original)
copy(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 uses Kryo.newInstance(Class)
.public T copy(Kryo kryo, T original)
Serializer
Serializer.isImmutable()
is true,
else throws KryoException
. Subclasses should override this method if needed to support Kryo.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 uses Kryo
to copy a child object may need to be reentrant.
This method should not be called directly, instead this serializer can be passed to Kryo
copy methods that accept a
serialier.
copy
in class Serializer<T>
public final Generics getGenericsScope()
Copyright © 2018. All rights reserved.