Unable to serialize Map when trying to store it in Hazelcast Cache

1.2k views Asked by At

I am trying to take data from DB and put in a Map and trying to store that map in hazelcast cache server.But its giving error

com.hazelcast.nio.serialization.HazelcastSerializationException: Failed to serialize 'java.util.TreeMap'.

Below is my code.

Map<Integer, List> cacheMap;
cacheMap = (Map<Integer, List>) hazelCastCache.getDataFromCache("CdnToIpConfig", key);

if(cacheMap == null)
{
  LOGGER.info("Cache memory is not allocated");  
  cacheMap = newTreeMap<>(); 
  cdnIpResDto =    configurationService.getCdnIpConfig(pageNo,sortBy,sortingOrder);
  responseDataRange = cdnIpResDto.getDtoList();  
  int lastIndexTracker =0;  
  for (int i = 1; i <= responseDataRange.size(); i++) {
       if (i % 10 == 0) {
            finalData = responseDataRange.subList(i - 10, i);
            cacheMap.put(pageNo, finalData);
            System.out.println(cacheMap);// I can see contents of cacheMap
            pageNo++;
            lastIndexTracker = i;
                   }
               }
   hazelCastCache.addDataToCache("CdnToIpConfig", key, cacheMap); 
   System.out.println("Data added in Hazelcast"); // This line is not getting executed.

Since last line print statement is not getting executed which means TreeMap is not getting added in cache.Any help Please??

1

There are 1 answers

0
mridul deka On

The problem that i was facing was In the code above i am taking a sublist which doesnt implements Serializable.So i wrapped the sublist inside a ArrayList and issue was resolved.Here is the modified code:--

finalData = new ArrayList(responseDataRange.subList(i - 10, i));