This topic discusses using VMware Tanzu GemFire’s DataSerializable interface for quick serialization of your objects.

Data Serialization with the DataSerializable Interface

Tanzu GemFire’s DataSerializable interface gives you faster and more compact data serialization than the standard Java serialization or Tanzu GemFire PDX serialization. However, while Tanzu GemFire DataSerializable interface is generally more performant than Tanzu GemFire’s PdxSerializable, it requires full deserialization on the server and then reserialization to send the data back to the client.

You can further speed serialization by registering the instantiator for your DataSerializable class through Instantiator, eliminating the need for reflection to find the right serializer. You can provide your own serialization through the API.

The recommended way to register your custom Instantiator is by specifying it in the serialization-registration element of cache.xml.

For more information, see the online Java documentation for DataSerializable and DataSerializer.

Example cache.xml:

The following provides an example of how to register an instantiator using cache.xml.

<serialization-registration>
  <instantiator id="30">
    <class-name>com.package.MyClass</class-name>
  </instantiator>
</serialization-registration>

In addition to speeding standard object serialization, you can use the DataSerializable interface to serialize any custom objects you store in the cache.

Serializing Your Domain Object with DataSerializer

You can also use DataSerializer to serialize domain objects. It serializes data in the same way as DataSerializable but allows you to serialize classes without modifying the domain class code.

See the JavaDocs on DataSerializable and DataSerializer for more information.

check-circle-line exclamation-circle-line close-line
Scroll to top icon