I’ve have a class called Expression that im trying to serialize using the following load()/save() functions. It used to work fine, after making some changes to my code and the Expression class, a call to in.readObject() throws ClassCastException.
The error message is:
java.lang.ClassCastException: java.lang.String cannot be cast to java.io.ObjectStreamClass
I’ve have a class called Expression that im trying to serialize using the following
Share
To me, it feels very bad to store binary data as a String. Try to use a more stable way to store the binary output of the ObjectOutputStream. If you really want to stick with a string formatted approach, try to use Base64 encoding, which is always safe.
What I might see as a problem is that you defined the serialUID yourself to a static constant:
This UID is used to determine if the classes in the class path are compatible with the class of the input object. So what I suspect is that you modified the class without changing the serialVersionUID. That made the ObjectInputStream think that is is compatible, but you are still working with old data. Try to get rid of the old data, and restart with a fresh
save()call.Are you sure that
Inputis serializable as well? That the UID of that class isn’t corrupt?