A newer version of Platform is available.

View latest

Serialization

To be able to send data over a network between cluster members and/or clients, you have to serialize it into raw bytes. Hazelcast has many serialization methods to choose from, depending on which Hazelcast topology you are using and what you plan on doing with your data.

Serialization in Client/Server Mode

In client/server topologies, you can serialize your data on the client side. For example, you can serialize data in JSON and add it to a map. This option is useful if you plan on using Hazelcast to store your data in binary. Clients can handle serialization without the members needing to know how to do so.

However, in the following cases, you must configure your serialization method on the member as well:

Case Clients Reason Exceptions

When the data structure’s values are stored as objects

All clients

Members must be able to serialize or deserialize the object in order to send it to other members or receive it from other members

When you want to process map entries or use an executor service

All clients

Members need to serialize the tasks

When using the Java client with Portable serialization, you don’t need to configure serialization on the member. For details, see Accessing Domain Objects Without Domain Classes.

When you use SQL queries on nested fields whose values are not primitives

Java only

Members need to deserialize underlying objects to be able to read nested fields

You can query nested fields whose values are primitives because these data types are serialized by Hazelcast by default. See Data Types with Built-In Serialization

Serialization Options for Clients

The following serialization options are available for clients:

  • IdentifiedDataSerializable

  • Portable

  • Compact (BETA)

  • Custom Serialization

For a comparison of these options, see Comparing Serialization Interfaces.

Serialization in Embedded Mode

In embedded mode, because data is partitioned across members in a cluster, each member must be able to serialize and deserialize data in the following cases:

  • Adding key/value objects to a map

  • Putting items in a queue/set/list

  • Sending a runnable using an executor service

  • Processing an entry within a map

  • Locking an object

  • Sending a message to a topic

Serialization Options for Members

For a full list of serialization options, see Comparing Serialization Interfaces.

Data Types with Built-In Serialization

By default, Hazelcast optimizes the serialization for the following data types. You do not need to serialize or deserialize these types yourself:

  • Class, Optional, Date, BigInteger, BigDecimal, ArrayList, LinkedList, CopyOnWriteArrayList/Set, HashMap/Set, ConcurrentSkipListMap/Set, ConcurrentHashMap, LinkedHashMap/Set, TreeMap/Set, ArrayDeque, LinkedBlockingQueue, ArrayBlockingQueue, PriorityBlockingQueue, PriorityQueue, DelayQueue, SynchronousQueue, LinkedTransferQueue

If you would rather implement your own serialization for these types, see Overriding the Default Serializers.