[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 389
  • Last Modified:

Advice needed on using ObjectInputStream/OutputStream for (de)serialization processes, how to keep older version readable?

In my software, I have a large class representing a document, which is saved to file using ObjectOutputStream and later read out by ObjectInputStream.  While everything's very convenient, problem arises every time I tried to modify anything in that class, or any class that the class references (of course those objects are saved along with the main document object) --- the new class won't be able to read old document any more and throws an exception about class ID not matching.

While this is expected behavior, it gets really annoying because if I do any upgrades, I would have to provide a way to migrate old files over.  Of course one way is to keep two sets of classes, the old one and convert to new one.  But once there're several versions, this is not going to be workable.

So my question is:

What would be the best way to solve this upgrade problem in my situation?  Namely, Is there anyway to easily read old objects without exception into new objects?  I never used resolveObject() but would it help? how?  Or should I abandon ObjectOutputStream etc. altogether and write my own class?  That would be a big hassle, however, and it has to be the very last resort.

Thanks in advance.
0
inq123
Asked:
inq123
  • 3
  • 3
2 Solutions
 
zzynxSoftware engineerCommented:
0
 
zzynxSoftware engineerCommented:
0
 
TimYatesCommented:
Or just use the XMLEncoder in java.beans.XMLEncoder
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
inq123Author Commented:
zzynx, thanks!  Although I havent tried it out but it should be the solution that I need.  Simple and effective.

TimYates, thanks for your answer.  It's interesting but it would involve more work (converting to public members and providing get/setters for all members) and produce a larger file I believe, so I probably won't use it.
0
 
TimYatesCommented:
Fair enough :-)

Glad to give you a different direction to investigate anyways ;-)

Good luck with it!!

Tim
0
 
zzynxSoftware engineerCommented:
Thanks for accepting
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now