Serialize Using the GemFire PDX Autoserializer
When you register the reflection-based serializer, GemFire uses it to serialize all objects that do not implement
IGeodeSerializable. You can customize the auto-serialization behavior for your domain objects by adding serialization attributes to your object’s fields.
If you have not already registered the PDX reflection-based autoserializer, add the registration code to your application.
using Apache.Geode.Client; ... // 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
(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
PdxInstancecomputes 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
IPdxTypeMapper to map Java types to .NET types. Note that you only need to use the
IPdxTypeMapperif 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
PdxIdentityFieldto the field.
[PdxIdentityField] private int id;
To exclude a field from serialization, add the .NET attribute
NonSerializedto the field.
[NonSerialized] private int myLocalData;
For each domain class GemFire serializes using the autoserializer, all fields are considered for serialization except those defined as
readonly and those you explicitly exclude using the .NET