Is there a way to determine the generated serialVersionUID
of a serialized Java object?
The problem is that I serialized an object without explicitely specifying the serialVersionUID
. Now the deserialization process complains about class incompatibilities. However I didn't change the class in a way which would make it incompatible. So I assume that it is enough to specify the serialVersionUID
in the class as it is stored in the object data. In order to do this I need to read the serialVersionUID
from the serialized data.
The easiest way to get it (especially on hard to find cases) is to define any number for serialVersionUID and monitor the stacktrace when the deserialization fails, it will print out the original one.
There is a specified grammar for the serialization of objects:
See chapter 6.4 in http://java.sun.com/javase/6/docs/platform/serialization/spec/serialTOC.html
Using this, you should be able to determine the SerialVersionUID of your serialized object.
That's exactly what you should do - specify your own
static final long serialVersionUID
.There's a section about it in the docs for Serializable.
Unless you've specified a
serialVersionUID
I don't believe there's an easy way to get it other than deciphering the stream as @WMR suggests.