How to determine a proper serial version ID? Should it be any big long value using some generators or any integer wld suffice ?
Frankly, as long as the serialVersionUID
differs between the different versions of your class, that's all that matters.
What would be bad is if there are two versions of the same class with differing serializable fields having the same serialVersionUID
-- that's probably going to cause a problem when performing serialization.
Additionally, if the changes to the class will not affect serialization (e.g. serializable fields in the class remain the same), then the serialVersionUID
can remain the same.
IDEs like Eclipse will automatically generate an ID for classes which implement Serializable
based on the fields and other information regarding the class, so that may be the easiest route to take to generate an unique ID.
For further reading on the topic, the Discover the secrets of the Java Serialization API would be a good read. There is a section called "Version Control" which discusses the serialVersionUID
issue.
The serialver tool comes with Sun's Java Development Kit (JDK). It takes a full class name on the command line and returns the serial version ID for that compiled class, or can be run with the "-show" parameter to launch a small interactive GUI.
So if your class is Foo, run
serialver Foo
and you'll get some sort of output like this:
Foo: static final long serialVersionUID = -6618469841127325812L;
Take the code starting with "static" and place it inside your class with other static variables. Now the serial version ID is locked in the class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With