Thank you for comment. I'll try to keep changing the UID as a habit
when changing the serialiable source file every time.
> Thank you for comment. I'll try to keep changing the UID as a habit
> when changing the serialiable source file every time.
It's only necessary to do this when field changes are made. In fact,
only when there's some nontransient field foo in the old version and
in the new version it's missing or it's of a more specific type or its
semantics are changed. Generally this means you renamed or deleted a
field, changed it to be of a subclass of whatever it used to be (e.g.
from Collection to List, or List to ArrayList), or changed the
semantics (e.g. double x, y, z used to be interpreted with z being
"up", and now is interpreted with y being "up", or vice-versa).
So when fields recorded basically as name=value pairs are read back in
there'd be nowhere for one to go, or a ClassCastException, or it would
seem to work but something would break further down the line.
Adding a field that can tolerably be left false, zero, or null when
old objects are read back in isn't a problem. If the added field
should have a sensible content, though, and old objects won't work if
this new field is left blank, change the version number.
There's some way of supporting older versions with explicit readObject
methods but you rarely want to.
Roedy Green - 31 Jul 2007 21:43 GMT
>> when changing the serialiable source file every time.
>It's only necessary to do this when field changes are made
see http://mindprod.com/jgloss/serialization.html#VERSIONING
for the general rules of thumb about what changes count as changes.
Follow the link there to the Sun site for the lawyer's version.

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
Lew - 01 Aug 2007 00:35 GMT
>>> when changing the serialiable source file every time.
>> It's only necessary to do this when field changes are made
>
> see http://mindprod.com/jgloss/serialization.html#VERSIONING
> for the general rules of thumb about what changes count as changes.
> Follow the link there to the Sun site for the lawyer's version.
Also pay close attention to Joshua Bloch's advice about serialization in
/Effective Java/. In summary, he points out that the serialization interface
(as implemented specifically for the class) is another public interface that
must be maintained for the life of the class, and protected from its unique
security and bug risks.
In addition to tricks such as Twisted's implicit recommendation to understand
the "transient" keyword, there are things to do with the readObject(),
writeObject(), readResolve() and other methods.
The trick is to maintain class invariants. You actually don't even really
need to provide a serialVersionUID to get serialization to work, for certain
values of "work". The Java system will make certain default decisions for
anything you don't explicitly implement in your serialization strategy. The
problem is that absent such a strategy they very well could be disastrous
decisions.

Signature
Lew