Wednesday, September 9, 2015

NotSerializableException

NotSerializableException if your code refers to a class that does not extend Java’s Serializable interface. It can be difficult to track down which class is causing the problem in this case, since many different classes can be referenced from user code. Many JVMs support a special option to help debug this situation: “-Dsun.io.serialization.extendedDebugInfo=true”.

Once you’ve found the class in question, the easiest solution is to simply modify it to implement Serializable. If you cannot modify the class in question you’ll need to use more advanced workarounds, such as creating a subclass of the type in question that implements Java’s Externalizable interface or customizing the serialization behavior using Kryo.

No comments:

Post a Comment