com.esotericsoftware.kryo.serialize
Class FieldSerializer

java.lang.Object
  extended by com.esotericsoftware.kryo.Serializer
      extended by com.esotericsoftware.kryo.serialize.FieldSerializer
Direct Known Subclasses:
ReferenceFieldSerializer

public class FieldSerializer
extends Serializer

Serializes objects using direct field assignment. This is a very fast mechanism for serializing objects, often as good as 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.

Author:
Nathan Sweet
See Also:
Serializer, Kryo.register(Class, Serializer)

Nested Class Summary
 class FieldSerializer.CachedField
          Controls how a field will be serialized.
 
Constructor Summary
FieldSerializer(Kryo kryo, java.lang.Class type)
           
 
Method Summary
 FieldSerializer.CachedField getField(java.lang.String fieldName)
          Allows specific fields to be optimized.
<T> T
readObjectData(java.nio.ByteBuffer buffer, java.lang.Class<T> type)
          Reads an object from the buffer.
protected
<T> T
readObjectData(T object, java.nio.ByteBuffer buffer, java.lang.Class<T> type)
           
 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.
 
Methods inherited from class com.esotericsoftware.kryo.Serializer
isFinal, newInstance, readObject, setCanBeNull, writeObject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FieldSerializer

public FieldSerializer(Kryo kryo,
                       java.lang.Class type)
Method Detail

setFieldsCanBeNull

public void setFieldsCanBeNull(boolean fieldsCanBeNull)
Sets the default value for FieldSerializer.CachedField.setCanBeNull(boolean).

Parameters:
fieldsCanBeNull - False if none of the fields are null. Saves 1 byte per field. True if it is not known (default).

setFieldsAsAccessible

public void setFieldsAsAccessible(boolean setFieldsAsAccessible)
Controls which fields are serialized.

Parameters:
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.

setIgnoreSyntheticFields

public void setIgnoreSyntheticFields(boolean ignoreSyntheticFields)
Controls if synthetic fields are serialized.

Parameters:
ignoreSyntheticFields - If true, only non-synthetic fields will be serialized (default). If false, synthetic fields will also be serialized.

writeObjectData

public void writeObjectData(java.nio.ByteBuffer buffer,
                            java.lang.Object object)
Description copied from class: Serializer
Writes the object to the buffer.

Specified by:
writeObjectData in class Serializer
object - Cannot be null.

readObjectData

public <T> T readObjectData(java.nio.ByteBuffer buffer,
                            java.lang.Class<T> type)
Description copied from class: Serializer
Reads an object from the buffer.

Specified by:
readObjectData in class Serializer
Returns:
The deserialized object, never null.

readObjectData

protected <T> T readObjectData(T object,
                               java.nio.ByteBuffer buffer,
                               java.lang.Class<T> type)

getField

public FieldSerializer.CachedField getField(java.lang.String fieldName)
Allows specific fields to be optimized.


removeField

public void removeField(java.lang.String fieldName)
Removes a field so that it won't be serialized.



Copyright © 2011. All Rights Reserved.