I am trying to set a list of objects(serializable) in Memcached client. I am doing it using the set method. I am getting this error message:
Exception occurred in target VM: Non-serializable object
So it’s not allowing me to set the value in the MemcachedClient object. Here’s my code:
MemcachedClient client = CacheConnectionUtil.connectToCacheServer(this.applicationEnv);
client.set(generateCacheKey(namespace, key), expireInSeconds, value);
// value is a list of objects that implements serializable
Why am I getting this error message?
From the
Serializablejavadocs:Memcached seems to be hiding the rest of the exception message, so you’ll have to identify the non-serializable object yourself.
You say that
valuesis a list of your own object. My guess is your object holds something that isn’t alsoSerializable, or it holds something that holds something else that isn’tSerializable. Go through the class of the objects in your list and make sure that every object underneath it implementsSerializable.As an example, if I have
AimplementsSerializable:And
Bdoesn’t:Then any attempt to serialize
Ausing anObjectOutputStream(which is probably what the default serializer in the Memcached library is doing) will throw aNotSerializableExceptionbecause its field,private B b, is a non-serializable type, which is what you’re getting.