Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Serializable not working with added field

0 views
Skip to first unread message

Bill Tschumy

unread,
Jun 19, 1997, 3:00:00 AM6/19/97
to

I have been using the Serializing capabilities in 1.1 to save some
objects to disk. I just added a new field to one of my objects that
get serialized and now deserializing my old data no longer works. I
get the following stack trace:

java.io.InvalidClassException: MacroData; Local class not compatible
at
java.io.ObjectStreamClass.setClass(ObjectStreamClass.java:219)
at
java.io.ObjectInputStream.inputClassDescriptor(ObjectInputStream.java:639)
at
java.io.ObjectInputStream.readObject(ObjectInputStream.java:276)
at
java.io.ObjectInputStream.inputObject(ObjectInputStream.java:820)
.
.
.
.

My understanding of the serialization is that I should be able to add
fields and still deserialize old data. This is from the docs on
Serialization:

"The defaultReadObject method uses information in the stream to assign
the fields of the object saved in the stream with the correspondingly
named fields in the current object. This handles the case when the
class has evolved to add new fields."

I have even tried marking the new field "transient", but I still get
the same exception. Any thoughts?

----
Bill Tschumy
Vignette Corp. -- Austin, TX
bi...@vignette.com


Bill Tschumy

unread,
Jun 19, 1997, 3:00:00 AM6/19/97
to

Well, I solved my own problem. Seems I needed to stick a

static final long serialVersionUID = 4021215565287364875L;

in my modified class. The actual value of this long is gotten from
the "serialver" utilitity suppied with the JDK. Any versions of a
class other than the first version require this static to be defined
in the class.

Happy coding.


On Thu, 19 Jun 1997 16:07:48 GMT, bi...@vignette.com (Bill Tschumy)
wrote:

0 new messages