0
votes

I have searched online for a few days, but only find that my object is not implementing serializable? Which object? DataKey or ResponseEntity? I can't reproduce this error in my local and I can only see this error in remote server log.

Updated: Since this issue is only happening when trying to refresh a cache object, first time load into cache does not have this issue, so I apply the fix by setting overflowToDisk="false" in ehcache.xml, and issue gone.

2020-03-30_12:15:30.941 [refdata.data] ERROR n.s.e.store.disk.DiskStorageFactory - Disk Write of DataKey [refDataType=Machine, subDataType=Laptop] failed:
java.io.NotSerializableException: org.springframework.http.ResponseEntity
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1184)2
        at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)
        at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:441)
        at net.sf.ehcache.Element.writeObject(Element.java:875)
        at sun.reflect.GeneratedMethodAccessor48.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:1028)
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1496)
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
        at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
        at net.sf.ehcache.util.MemoryEfficientByteArrayOutputStream.serialize(MemoryEfficientByteArrayOutputStream.java:97)
        at net.sf.ehcache.store.disk.DiskStorageFactory.serializeElement(DiskStorageFactory.java:403)
        at net.sf.ehcache.store.disk.DiskStorageFactory.write(DiskStorageFactory.java:385)
        at net.sf.ehcache.store.disk.DiskStorageFactory$DiskWriteTask.call(DiskStorageFactory.java:477)
        at net.sf.ehcache.store.disk.DiskStorageFactory$PersistentDiskWriteTask.call(DiskStorageFactory.java:1071)
        at net.sf.ehcache.store.disk.DiskStorageFactory$PersistentDiskWriteTask.call(DiskStorageFactory.java:1055)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run
java.io.NotSerializableException: org.springframework.http.ResponseEntity is perfectly clear. You shouldn't be trying to cache a response. - user207421
yeah... you are serializaing a ResponseEntity or you are referencing to one in one of your serializable objects. - Amir Pashazadeh
Whether it's good to cache a response or not - clearly it needs to be Serializable (i.e. implement the Serializable interface) if you want to cache it. If you look at ResponseEntity javadoc it clearly isn't serializable - which is why you got the error. Of course you could cache the body() and that should work. - Mr R
@user207421, But this error only appear when I do ehcache refresh, first time load does not have this issue. Do you know why? - FullStackDeveloper
@Amir Pashazadeh But this error only appear when I do ehcache refresh, first time load does not have this issue. Do you know why? - FullStackDeveloper