com.esotericsoftware.kryo
Class Serializer

java.lang.Object
  extended by com.esotericsoftware.kryo.Serializer
Direct Known Subclasses:
ArraySerializer, BeanSerializer, BigDecimalSerializer, BigIntegerSerializer, BooleanSerializer, ByteSerializer, CharSerializer, CollectionSerializer, CompatibleFieldSerializer, Compressor, CustomSerializer, DateSerializer, DoubleSerializer, EnumSerializer, FieldSerializer, FloatSerializer, IntSerializer, LongSerializer, MapSerializer, SerializableSerializer, ShortSerializer, SimpleSerializer, StringSerializer

public abstract class Serializer
extends java.lang.Object

Serializes objects to and from a ByteBuffer.

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

Constructor Summary
Serializer()
           
 
Method Summary
 boolean isFinal(java.lang.Class type)
          Returns true if the specified type is final, or if it is an array of a final type.
<T> T
newInstance(Kryo kryo, java.lang.Class<T> type)
          Returns an instance of the specified class.
<T> T
readObject(java.nio.ByteBuffer buffer, java.lang.Class<T> type)
          Reads an object from the buffer.
abstract
<T> T
readObjectData(java.nio.ByteBuffer buffer, java.lang.Class<T> type)
          Reads an object from the buffer.
 void setCanBeNull(boolean canBeNull)
          When true, a byte will not be used to denote if the object is null.
 void writeObject(java.nio.ByteBuffer buffer, java.lang.Object object)
          Writes the object to the buffer.
abstract  void writeObjectData(java.nio.ByteBuffer buffer, java.lang.Object object)
          Writes the object to the buffer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Serializer

public Serializer()
Method Detail

setCanBeNull

public void setCanBeNull(boolean canBeNull)
When true, a byte will not be used to denote if the object is null. This is useful for primitives and objects that are known to never be null. Defaults to true.


writeObject

public final void writeObject(java.nio.ByteBuffer buffer,
                              java.lang.Object object)
Writes the object to the buffer.

Parameters:
object - Can be null (writes a special class ID for a null object instead).

writeObjectData

public abstract void writeObjectData(java.nio.ByteBuffer buffer,
                                     java.lang.Object object)
Writes the object to the buffer.

Parameters:
object - Cannot be null.

readObject

public final <T> T readObject(java.nio.ByteBuffer buffer,
                              java.lang.Class<T> type)
Reads an object from the buffer.

Returns:
The deserialized object, or null if the object read from the buffer was a null.

readObjectData

public abstract <T> T readObjectData(java.nio.ByteBuffer buffer,
                                     java.lang.Class<T> type)
Reads an object from the buffer.

Returns:
The deserialized object, never null.

newInstance

public <T> T newInstance(Kryo kryo,
                         java.lang.Class<T> type)
Returns an instance of the specified class. The default implementation calls Kryo.newInstance(Class).

Throws:
SerializationException - if the class could not be constructed.

isFinal

public boolean isFinal(java.lang.Class type)
Returns true if the specified type is final, or if it is an array of a final type. Serializers call this rather than Kryo.isFinal(Class), allowing a subclass to customize the behavior (eg, an application may decide that all java.util.ArrayList instances should be considered final).



Copyright © 2011. All Rights Reserved.