public class FieldSerializer extends Serializer
CustomSerialization
. FieldSerializer is many times smaller and faster than Java serialization. The fields should be
public for optimal performance, which allows bytecode generation to be used instead of reflection.
FieldSerializer does not write header data, only the object data is stored. If the type of a field is not final (note primitives are final) then an extra byte is written for that field.
Serializer
,
Kryo.register(Class, Serializer)
Modifier and Type | Class and Description |
---|---|
class |
FieldSerializer.CachedField
Controls how a field will be serialized.
|
Constructor and Description |
---|
FieldSerializer(Kryo kryo,
java.lang.Class type) |
Modifier and Type | Method and Description |
---|---|
FieldSerializer.CachedField |
getField(java.lang.String fieldName)
Allows specific fields to be optimized.
|
FieldSerializer.CachedField[] |
getFields() |
<T> T |
readObjectData(java.nio.ByteBuffer buffer,
java.lang.Class<T> type)
Reads an object from the buffer.
|
void |
removeField(java.lang.String fieldName)
Removes a field so that it won't be serialized.
|
void |
setFieldsAsAccessible(boolean setFieldsAsAccessible)
Controls which fields are serialized.
|
void |
setFieldsCanBeNull(boolean fieldsCanBeNull)
Sets the default value for
FieldSerializer.CachedField.setCanBeNull(boolean) . |
void |
setIgnoreSyntheticFields(boolean ignoreSyntheticFields)
Controls if synthetic fields are serialized.
|
void |
writeObjectData(java.nio.ByteBuffer buffer,
java.lang.Object object)
Writes the object to the buffer.
|
isFinal, newInstance, readObject, setCanBeNull, writeObject
public FieldSerializer(Kryo kryo, java.lang.Class type)
public void setFieldsCanBeNull(boolean fieldsCanBeNull)
FieldSerializer.CachedField.setCanBeNull(boolean)
.fieldsCanBeNull
- False if none of the fields are null. Saves 1 byte per field. True if it is not known (default).public void setFieldsAsAccessible(boolean setFieldsAsAccessible)
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)
ignoreSyntheticFields
- If true, only non-synthetic fields will be serialized (default). If false, synthetic fields
will also be serialized.public void writeObjectData(java.nio.ByteBuffer buffer, java.lang.Object object)
Serializer
writeObjectData
in class Serializer
object
- Cannot be null.public <T> T readObjectData(java.nio.ByteBuffer buffer, java.lang.Class<T> type)
Serializer
readObjectData
in class Serializer
public FieldSerializer.CachedField getField(java.lang.String fieldName)
public void removeField(java.lang.String fieldName)
public FieldSerializer.CachedField[] getFields()