Search code examples
serializationhazelcastspring-cache

Hazelcast serialization exception on nested Object


I'm using Spring Boot 1.5.1 and Hazelcast 3.7.5.
I get a NotSerializableException when caching an object of this entity (GeoPoint is not serializable):

public class Test implements Serializable {
      private String title;
      private GeoPoint location;
}

I have added a custom serializer for this field:

SerializerConfig sc = new SerializerConfig()
            .setImplementation(new GeoPointSerializer())
            .setTypeClass(GeoPoint.class);
config.getSerializationConfig().addSerializerConfig(sc);

But the exception remains.
It does work when I cache a GeoPoint directly:

@Cacheable("point")
public GeoPoint test() {
    return new GeoPoint(0, 0);
}

How can I tell Hazelcast to use my custom serializer for the field?


Solution

  • Whenever you hand off serialization to Java Serialization (Serializable or Externalizable) internal serialization schemes won't work anymore. It is basically, once Serializable, forever Serializable. That said there are two options, make class "Test" at least DataSerializable or make class "GeoPoint" Serializable / Externalizable.