Harikumar A
Harikumar A

Reputation: 151

Java objects cannot be deserialized because of class structure change

I had serialized some objects of class into a file later the class structure had modified. So I cannot deserialize my object back. Please let me know how can I restore these objects?

Upvotes: 1

Views: 198

Answers (2)

npinti
npinti

Reputation: 52205

You could:

  1. Revert your class as it was before.
  2. Create a new class which will have the new features.
  3. Write an adapter class which places one class (the old) into another (the new).
  4. Serialize the new version.

Upvotes: 1

Gerard Rozsavolgyi
Gerard Rozsavolgyi

Reputation: 5074

To make it short: You should use your previous version of your java class and use it to read the serialized objects. Then you'll have to make a transition piece of software reading previous data and filling fields in the new object with this data before serializing this new version of your object.

Upvotes: 3

Related Questions