Serialize Using the GemFire PDX Autoserializer
Serialize Using the GemFire PDX Autoserializer
When you register the reflection-based serializer, GemFire uses it to serialize all objects that do not implement IPdxSerializable or IGFSerializable. You can customize the auto-serialization behavior for your domain objects by adding serialization attributes to your object’s fields.
Procedure
- If you have not already registered the
PDX reflection-based autoserializer, add the registration code to your
application. For example:
using GemStone.GemFire.Cache.Generic; ... // Register reflection-based autoserializer to serialize // domain objects using PDX serialization Serializable.RegisterPdxSerializer(new ReflectionBasedAutoSerializer());
This can only be configured in the application code. It cannot be configured declaratively in cache.xml. - (Optional) For each object you intend
to have autoserialized, customize the serialization as needed. Note: If you also use PDX serialization in Java for the object, customize your serialization the same for both languages.
- The following extension methods
apply to autoserialization:
- WriteTransform. Controls what field value is written during auto serialization.
- ReadTransform. Controls what field value is read during auto deserialization.
- GetFieldType. Defines the specific field names that will be generated during autoserialization.
- IsIdentityField. Controls which field is marked as the identity field. Identity fields are used when a PdxInstance computes its hash code to determine whether it is equal to another object.
- GetFieldType. Determines the field type that will be used when autoserializing the given field.
- IsFieldIncluded. Specifies which fields of a class to autoserialize.
See Extending the Autoserializer for sample usage.
- If you are writing a Java
application, you can use the IPdxType Mapper to map
Java types to .NET types. Note that you only need to use the
IPdxTypeMapper if you are writing Java
applications.
See Map .NET Domain Type Names to PDX Type Names with IPdxTypeMapper for sample usage.
-
To specify an identifier field in your domain object, add the attribute PdxIdentityField to the field.
For example:[PdxIdentityField] private int id;
-
To exclude a field from serialization, add the .NET attribute NonSerialized to the field.
For example:[NonSerialized] private int myLocalData;
- The following extension methods
apply to autoserialization:
For each domain class GemFire serializes using the autoserializer, all fields are considered for serialization except those defined as static, literal or readonly and those you explicitly exclude using the .NET NonSerialized attribute.