| --- | |
| title: Data Serialization Options | |
| --- | |
| <!-- | |
| 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. | |
| --> | |
| The C++ client API gives two serialization options: <%=vars.product_name%> PDX serialization and the `apache::geode::client::DataSerializable` interface. | |
| <%=vars.product_name%> Portable Data eXchange (PDX) serialization is the recommended option. PDX | |
| serialization provides portability for PDX serializable objects so that clients can share data with | |
| Java servers and other non-C++ clients. PDX is a cross-language data format that can reduce the cost | |
| of distributing and serializing your objects. PDX stores data in named fields that you can access | |
| individually in order to avoid the cost of deserializing the entire data object. PDX also allows you | |
| to mix versions of objects where you have added or removed fields. | |
| When using PDX serialization, you can use either `PdxSerializable` (for a specific domain object) or `PdxSerializer` (for all your domain objects). | |
| `PdxSerializable` is used when the domain class that a user wants to serialize/deserialize is inherited from the `PdxSerializable` interface, and the user has registered the domain class using the `registerPdxType(domainClass)` API. | |
| `PdxSerializer` is used when a user has registered a domain class for serialization in the cache using the `registerPdxSerializer` API. | |
| The non-PDX serialization option is to use the `apache::geode::client::DataSerializable` interface. This | |
| `DataSerializable` interface can be a good option performance-wise if the size of your objects is | |
| small. `DataSerializable` is used whenever a user domain class is not inherited by `PdxSerializable`, | |
| but the user has registered the class with the `registerType` API. | |
| <table> | |
| <caption><span class="tablecap">Table 1. Serialization Options—Comparison of Features</span></caption> | |
| <colgroup> | |
| <col width="50%" /> | |
| <col width="25%" /> | |
| <col width="25%" /> | |
| </colgroup> | |
| <thead> | |
| <tr class="header"> | |
| <th>Capability</th> | |
| <th>DataSerializable</th> | |
| <th>PdxSerializable</th> | |
| </tr> | |
| </thead> | |
| <tbody> | |
| <tr class="odd"> | |
| <td><p>Handles multiple versions of domain objects</p></td> | |
| <td></td> | |
| <td>X</td> | |
| </tr> | |
| <tr class="even"> | |
| <td><p>Provides single field access on servers of serialized data, without full deserialization. Supported also for OQL queries.</p></td> | |
| <td></td> | |
| <td>X</td> | |
| </tr> | |
| <tr class="odd"> | |
| <td><p>Automatically ported to other languages by <%=vars.product_name%> - no need to program Java-side implementation</p></td> | |
| <td></td> | |
| <td>X</td> | |
| </tr> | |
| <tr class="even"> | |
| <td><p>Works with Geode delta propagation</p></td> | |
| <td>X</td> | |
| <td>X</td> | |
| </tr> | |
| </tbody> | |
| </table> | |
| <span class="tablecap">**Table 1.** Serialization Options—Comparison of Features</span> | |
| ## Important points to remember when using DataSerializable | |
| 1. Make sure to register the proper typeId when registering custom classes that have a corresponding server side jar (e.g. Portfolio and Position) | |
| 2. Make sure to register any custom types in each process that uses those types. The cppcache framework uses four separate processes. |