blob: 3019187bb4e86b5a46de4f56009cf2de9403b1ab [file] [log] [blame]
<% set_title("Serialize Using the", product_name, "PDX Autoserializer") %>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
When you register the reflection-based serializer, <%=vars.product_name%> uses it to serialize all objects that do not implement `IPdxSerializable` or `IDataSerializable`. You can customize the auto-serialization behavior for your domain objects by adding serialization attributes to your object’s fields.
**Procedure**
1. If you have not already registered the PDX reflection-based autoserializer, add the registration code to your application.
For example:
``` pre
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 `cache.xml`.
2. (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.
1. 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](extending-pdx-autoserializer.html#concept_87701FF3FAE74F3193BE3FB349CE0086) for sample usage.
2. 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](mapping-dotnet-domain-type-names.html#concept_63F4164F1AE242A9BA309738F484182D) for sample usage.
3. To specify an identifier field in your domain object, add the attribute `PdxIdentityField` to the field.
For example:
``` pre
[PdxIdentityField] private int id;
```
4. To exclude a field from serialization, add the .NET attribute `NonSerialized` to the field.
For example:
``` pre
[NonSerialized] private int myLocalData;
```
For each domain class <%=vars.product_name%> 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.