Not if your class includes this:
public static final long serialVersionUID = 1; /* Version 1 of the class */
This way you override the default serialVersionUID value which is formed
from the totality of the class' method signatures by the JVM. Objects with
serialVersionUID explicitly defined in the class will always be
de-serializable, regardless of the changes between versions, and will span
different Java releases.
I've been using this technique for years, and my serialized objects, stores
as blobs in DB, survived the transition from Java 1.2 to 1.5, with each and
every release in between.
Alex Molochnikov
Gestalt Corporation
> It's an incredibly terrible idea to store long term data as serialised
> files. This is because in order to unserialise the file into a class,
> you must have a copy of the original class file. So if you make ANY
> changes to the class, the serialised class stored in the file will not
> be able to be restored using the changed class.
Richard Wheeldon - 12 Feb 2006 19:11 GMT
> Not if your class includes this:
>
> public static final long serialVersionUID = 1; /* Version 1 of the class */
You also need to make sure your new fields are marked transient if you
want to be backward compatible with the old class structure. This is
important if the data may need to be used on an old version of the
program but is probably not be an issue if you're dealing with webapps.
Richard
Alex Molochnikov - 12 Feb 2006 20:30 GMT
You probably mean "forward compatible" - i.e. the old version of the class
may have to be de-serialized from the data generated by serializing the
newer version. The backward compatibility in serialization is not a
problem - the new class, with added non-transient fields can always be
de-serialized from an older version. In this case, the newly added fields
will be set to the default values (0 for numeric primitive types, false for
boolean, null for anything that is an object).
> > Not if your class includes this:
> >
[quoted text clipped - 6 lines]
>
> Richard
Richard Wheeldon - 12 Feb 2006 20:48 GMT
> You probably mean "forward compatible" - i.e. the old version of the class
> may have to be de-serialized from the data generated by serializing the
> newer version.
That's exactly what I meant,
Richard
Roedy Green - 13 Feb 2006 08:56 GMT
On Sun, 12 Feb 2006 20:30:29 GMT, "Alex Molochnikov"
<NOBODY@NOSPAM.COM> wrote, quoted or indirectly quoted someone who
said :
>You probably mean "forward compatible" -
see http://mindprod.com/jgloss/compatibility.html
http://mindprod.com/jgloss/forwardcompatibility.html
http://mindprod.com/jgloss/backwardcompatibility.html

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.