Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nested collections in Hazelcast IMap

I have a hazelcast instance and I am getting a map from it.

IMap<Object,Object> cache= hazelCastInstance.getMap(collectionName);

I want to store a nested collection (e.g. List < List< Definition > >) into it.

Definition => Class (This implements serializable)

cache.set(cacheKey, object, ttl,TimeUnit.SECONDS);

cacheKey => unique key

object => nested collection

ttl => time to live

I am getting an exception: java.io.NotSerializableException: java.util.ArrayList$SubList

I am using hazelcast for the first time. Does anyone have any idea why is that?

Please advice.

Thanks

like image 380
Vivek Avatar asked Mar 24 '26 03:03

Vivek


1 Answers

The error is caused by the ArrayList$Sublist not being serializable. It can be resolved by replacing your code by something like this:

cache.set(cacheKey, new ArrayList(objects), ttl, SECONDS)

Now you got rid of the inner class that is causing problems. The content of the sublist will be copied into a normal ArrayList and there are no problems serializing that.

like image 164
pveentjer Avatar answered Mar 25 '26 17:03

pveentjer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!