Advice needed on using ObjectInputStream/OutputStream for (de)serialization processes, how to keep older version readable?
Posted on 2004-11-22
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.