Package com.tangosol.io.pof
Class PortableTypeSerializer<T>
- java.lang.Object
-
- com.tangosol.io.pof.PortableTypeSerializer<T>
-
- All Implemented Interfaces:
PofSerializer<T>
public class PortableTypeSerializer<T> extends Object implements PofSerializer<T>
APofSerializer
implementation that serializes classes that implementPortableObject
interface (and optionallyEvolvableObject
interface).Unlike legacy
PortableObjectSerializer
, this class serializes attributes of each class in the object's hierarchy into a separate nested POF stream, which allows for independent evolution of each class in the hierarchy, as well as the evolution of the hierarchy itself (addition of new classes at any level in the hierarchy).- Since:
- 12.2.1
- Author:
- as 2013.05.01
-
-
Field Summary
Fields Modifier and Type Field Description protected int
m_nTypeId
The type identifier of the user type to serialize and deserialize.
-
Constructor Summary
Constructors Constructor Description PortableTypeSerializer(int nTypeId, Class<T> clazz)
Create a new PortableTypeSerializer for the user type with the given type identifier and class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description T
deserialize(PofReader reader)
Deserialize a user type instance from a POF stream by reading its state using the specified PofReader object.protected Class<?>
getClassForTypeId(PofContext ctx, int nTypeId)
Return the class associated with a specified type identifier, or null if the identifier is not defined in the current POF context.void
serialize(PofWriter writer, T value)
Serialize a user type instance to a POF stream by writing its state using the specified PofWriter object.
-
-
-
Constructor Detail
-
PortableTypeSerializer
public PortableTypeSerializer(int nTypeId, Class<T> clazz)
Create a new PortableTypeSerializer for the user type with the given type identifier and class.- Parameters:
nTypeId
- the type identifier of the user type to serialize and deserializeclazz
- the class of the user type to serialize and deserialize
-
-
Method Detail
-
serialize
public void serialize(PofWriter writer, T value) throws IOException
Description copied from interface:PofSerializer
Serialize a user type instance to a POF stream by writing its state using the specified PofWriter object.An implementation of PofSerializer is required to follow the following steps in sequence for writing out an object of a user type:
- If the object is evolvable, the implementation must set the version
by calling
PofWriter.setVersionId(int)
. - The implementation may write any combination of the properties of the user type by using the "write" methods of the PofWriter, but it must do so in the order of the property indexes.
- After all desired properties of the user type have been written,
the implementation must terminate the writing of the user type by
calling
PofWriter.writeRemainder(com.tangosol.util.Binary)
.
- Specified by:
serialize
in interfacePofSerializer<T>
- Parameters:
writer
- the PofWriter with which to write the object's statevalue
- the object to serialize- Throws:
IOException
- if an I/O error occurs
- If the object is evolvable, the implementation must set the version
by calling
-
deserialize
public T deserialize(PofReader reader) throws IOException
Description copied from interface:PofSerializer
Deserialize a user type instance from a POF stream by reading its state using the specified PofReader object.An implementation of PofSerializer is required to follow the following steps in sequence for reading in an object of a user type:
- If the object is evolvable, the implementation must get the version
by calling
PofReader.getVersionId()
. - The implementation may read any combination of the properties of
the user type by using "read" methods of the PofReader, but it must
do so in the order of the property indexes. Additionally, the
implementation must call
PofReader.registerIdentity(java.lang.Object)
with the new instance prior to reading any properties which are user type instances themselves. - After all desired properties of the user type have been read, the
implementation must terminate the reading of the user type by
calling
PofReader.readRemainder()
.
- Specified by:
deserialize
in interfacePofSerializer<T>
- Parameters:
reader
- the PofReader with which to read the object's state- Returns:
- the deserialized user type instance
- Throws:
IOException
- if an I/O error occurs
- If the object is evolvable, the implementation must get the version
by calling
-
getClassForTypeId
protected Class<?> getClassForTypeId(PofContext ctx, int nTypeId)
Return the class associated with a specified type identifier, or null if the identifier is not defined in the current POF context.- Parameters:
ctx
- the POF contextnTypeId
- the type identifier to lookup- Returns:
- the class associated with a specified type identifier, or null if the identifier is not defined in the current POF context
-
-