Serialization Interface Types
For complex objects, use the following interfaces for serialization and deserialization:
-
java.io.Serializable
: See the Implementing Java Serializable and Externalizable section. -
java.io.Externalizable
: See the Implementing Java Externalizable section. -
com.hazelcast.nio.serialization.DataSerializable
: See the Implementing DataSerializable section. -
com.hazelcast.nio.serialization.IdentifiedDataSerializable
: See the IdentifiedDataSerializable section. -
com.hazelcast.nio.serialization.Portable
: See the Implementing Portable Serialization section. -
Custom Serialization (using StreamSerializer and ByteArraySerializer).
-
Global Serializer: See the Global Serializer section for details.
-
Compact Serialization (BETA) (with CompactSerializer or Zero-Configuration)
When Hazelcast serializes an object:
-
It first checks whether the object is
null
. -
If the above check fails, and the Compact Serialization (BETA) is enabled, then Hazelcast looks for a user-specified CompactSerializer.
-
If the above check fails, then Hazelcast checks if it is an instance of
com.hazelcast.nio.serialization.DataSerializable
orcom.hazelcast.nio.serialization.IdentifiedDataSerializable
. -
If the above check fails, then Hazelcast checks if it is an instance of
com.hazelcast.nio.serialization.Portable
. -
If the above check fails, then Hazelcast checks if it is an instance of one of the default types (see the Serialization chapter introduction for default types).
-
If the above check fails, then Hazelcast looks for a user-specified Custom Serializer, i.e. an implementation of
ByteArraySerializer
orStreamSerializer
. Custom serializer is searched using the input Object’s Class and its parent class up to Object. If parent class search fails, all interfaces implemented by the class are also checked (excludingjava.io.Serializable
andjava.io.Externalizable
). -
If the above check fails, then Hazelcast checks if it is an instance of
java.io.Serializable
orjava.io.Externalizable
and a Global Serializer is not registered with Java Serialization Override feature. -
If the above check fails, Hazelcast uses the registered Global Serializer if one exists.
-
If the above check fails, and the Compact Serialization (BETA) is enabled, then Hazelcast tries to extract a schema out of the Object’s class automatically, if possible.
If all the above checks fail, then serialization fails. When a class implements multiple interfaces, the above steps are important to determine the serialization mechanism that Hazelcast uses. When a class definition is required for any of these serializations, you need to have all the classes needed by the application on your classpath because Hazelcast does not download them automatically, unless you are using user code deployment.