O
- object typepublic abstract class CustomSerializer<O>
extends java.lang.Object
Custom serializers should extend this class. An instance of the class implementing this interface should
be passed to NamedCache.setCustomSerialization(com.scaleoutsoftware.soss.client.CustomSerializer)
.
This class does not have any built-in routine for type checking. The type information should be saved and
retrieved manually. Use this interface only when full control over the byte stream is necessary. In all other cases
it might be safer to customize serialization by using objects that implement the Externalizable
interface.
Externalizable
allows control over most of the serialization format, but preserves standard Java typing
data, so objects will be automatically deserialized as the correct type. Using a CustomSerializer is
advisable when implementing portable Java/C# objects.
If serialization or deserialization of an object is not supported in its implementation, it should throw an
ObjectNotSupportedException
. This will trigger an attempt to fallback to standard serialization.
However, it is not recommended to keep such objects in the cache when a custom serializer is defined.
You can use a "magic number" in the beginning of the stream to distinguish custom serialized objects from ones
using standard serialization. The standard Java serializer always uses 0xACED as the stream prefix.
Modifier and Type | Field and Description |
---|---|
protected java.lang.Class<O> |
objectClass |
Modifier | Constructor and Description |
---|---|
protected |
CustomSerializer() |
Modifier and Type | Method and Description |
---|---|
abstract O |
deserialize(java.io.InputStream in)
Deserializes an object from
InputStream . |
O |
deserialize(java.io.InputStream in,
O instanceToSet)
Deserializes an object from
InputStream . |
java.lang.Class<O> |
getObjectClass()
Returns the class for the object.
|
int |
getSize()
Returns size of fixed size objects.
|
abstract void |
serialize(java.io.OutputStream out,
O o)
Serializes an object to
OutputStream . |
void |
setObjectClass(java.lang.Class<O> objectClass)
Sets the class of the serialized/deserialized objects.
|
protected java.lang.Class<O> objectClass
public abstract void serialize(java.io.OutputStream out, O o) throws ObjectNotSupportedException, java.io.IOException
OutputStream
.out
- output streamo
- object to be serializedObjectNotSupportedException
- if this object cannot be serializedjava.io.IOException
- if serializer experiences an input/output errorpublic abstract O deserialize(java.io.InputStream in) throws ObjectNotSupportedException, java.io.IOException, java.lang.ClassNotFoundException
InputStream
.in
- input streamObjectNotSupportedException
- if this object cannot be deserializedjava.io.IOException
- if the serializer experiences an input/output errorjava.lang.ClassNotFoundException
- if the dependency is not loaded into the JVMpublic O deserialize(java.io.InputStream in, O instanceToSet) throws ObjectNotSupportedException, java.io.IOException, java.lang.ClassNotFoundException
InputStream
.in
- input streaminstanceToSet
- the object to deserializeObjectNotSupportedException
- if this object cannot be deserializedjava.io.IOException
- if serializer experiences an input/output errorjava.lang.ClassNotFoundException
- if the dependency is not loaded into the JVMpublic void setObjectClass(java.lang.Class<O> objectClass)
objectClass
- class of the objectpublic java.lang.Class<O> getObjectClass()
public int getSize()