Gemfire JavaDocs_test
Interface PdxSerializer
-
- All Known Implementing Classes:
ReflectionBasedAutoSerializer
public interface PdxSerializer
The PdxSerializer interface allows domain classes to be serialized and deserialized as PDXs without modification of the domain class. It only requires that the domain class have a public zero-arg constructor and that it provides read and write access to the PDX serialized fields.GemFire allows a single PdxSerializer to be configured on a cache using
setPdxSerializer
orclient setPdxSerializer
. It can also be configured incache.xml
using thepdx-serializer
element. The same PdxSerializer should be configured on each member of a distributed system that can serialize or deserialize PDX data.The
toData
method is used for serialization;fromData
is used for deserialization. The order in which fields are serialized and deserialized in these methods for the same class must match. For the same class toData and fromData must write the same fields each time they are called.If you can modify your domain class then use
PdxSerializable
instead.Simple example:
public class User { public final String name; public final int userId; public User(String name, int userId) { this.name = name; this.userId = userId; } } public class MyPdxSerializer implements PdxSerializer { public boolean toData(Object o, PdxWriter out) { if (o instanceof User) { User u = (User) o; out.writeString("name", u.name); out.writeInt("userId", u.userId); return true; } else { return false; } } public Object fromData(Class<?> clazz, PdxReader in) { if (User.class.isAssignableFrom(clazz)) { return new User(in.readString("name"), in.readInt("userId")); } else { return null; } } }
- Since:
- GemFire 6.6
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.lang.Object
fromData(java.lang.Class<?> clazz, PdxReader in)
This method is given an class that should be instantiated and deserialized using the given reader.boolean
toData(java.lang.Object o, PdxWriter out)
This method is given an object to serialize as a PDX using the given writer.
-
-
-
Method Detail
-
toData
boolean toData(java.lang.Object o, PdxWriter out)
This method is given an object to serialize as a PDX using the given writer. If it chooses to do the serialization then it must returntrue
; otherwise it must returnfalse
in which case it will be serialized using standard serialization.- Parameters:
o
- the object to consider serializing as a PDXout
- thePdxWriter
to use to serialize the object- Returns:
true
if the method serialized the object; otherwisefalse
-
fromData
java.lang.Object fromData(java.lang.Class<?> clazz, PdxReader in)
This method is given an class that should be instantiated and deserialized using the given reader.- Parameters:
clazz
- the Class of the object that should be deserializedin
- the reader to use to obtain the field data- Returns:
- the deserialized object.
null
indicates that this PdxSerializer does not know how to deserialize the given class.
-
-