简体   繁体   中英

Hazelcast : NotSerializableException

I am using a map with Hazelcast :

//When I do :

map.put(gen.newId(), myObject);

myObject is a very complex object and does not implements Serializable.

I thought that putting the config like below was enough for not having to implement serializable :

<map name="myMap">
    <in-memory-format>OBJECT</in-memory-format>   
</map>

The Hazelcast doc says : http://docs.hazelcast.org/docs/3.5/manual/html/entryprocessor.html "When it is stored as an object (OBJECT format), then the entry processor is applied directly on the object. In that case, no serialization or deserialization is performed"

Thanks for any suggestion.

Unfortunately the object will always be deserialized when the map.put is called, no matter the in memory format. This is because normally there are backups and they need to receive a copy as well. So in this case your only way out is to make your object 'serializable'. You can use Java serialization, but you can also rely on something like Kryo to deal with complex object graphs.

I think you could also use more efficient hazelcast specific solutions. Here is a comparison table of the solutions. Portable has been working for me but is a pain in the ass to implement and maintain for big objects. DataSerializable is a more easy solution and looks a lot like Parcelable from Android.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM