user1841247
user1841247

Reputation: 413

Exception in serialize with transient field

I had some class which is used for storing state of the application. I need to serialize and deserialize it in/from file. It worked without problem. Now I added a new transient field to it, and, of cource, I coldn't deserialize my old files. I deleted this new transient field in order to have got ability to open old files, but I couldn't do it again! I got the following exception:

com.qqer.fuzzy.app.ApplicationCurrentState; local class incompatible: stream classdesc serialVersionUID = 6313827182653283573, local class serialVersionUID = 1

How can I fix it? I thought that I could just delete all new fields and all will be ok.

Upvotes: 1

Views: 373

Answers (2)

JB Nizet
JB Nizet

Reputation: 691635

Change the value of your serialVersionUID static field from 1 to 6313827182653283573, since that's the value it had when you serialized the object.

This will make it possible to deserialize the object, provided the class still has the exact same non-transient fields as it had when serializing it (which could not be true, since you introduced or changed the serialVersionUID field since then and forgot about it).

Upvotes: 2

Sergii Zagriichuk
Sergii Zagriichuk

Reputation: 5399

you wil help serialver set new version to all old classes, and all will be OK

Upvotes: 0

Related Questions