Cleaning up bad stream data
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Dave_Gross
Posted On:   Thursday, July 25, 2002 09:05 AM

I have a Serializable class that has an attribute which is a class from 3rd party software that did not handle Serialization in a backward compatible way (SUID's don't match, no readObject/writeObject to handle incompatibilities). This means if I upgrade to a new version of their class, I cannot read my old stream data unless I somehow skip their class in the stream and reconstruct their object. I can do this upgrade in two steps (but would like to know if there is a way to do it in one) 1. With old class in classpath, reserialize the data in a foreign format in a new attribute 2. With new class in classpath, rebuild the object from the other attribute That requires two deployment steps for my use   More>>

I have a Serializable class that has an attribute which is a class from 3rd party software that did not handle Serialization in a backward compatible way (SUID's don't match, no readObject/writeObject to handle incompatibilities). This means if I upgrade to a new version of their class, I cannot read my old stream data unless I somehow skip their class in the stream and reconstruct their object.


I can do this upgrade in two steps (but would like to know if there is a way to do it in one)

1. With old class in classpath, reserialize the data in a foreign format in a new attribute

2. With new class in classpath, rebuild the object from the other attribute


That requires two deployment steps for my users, which I would like to avoid, but I don't see a clean solution.


What I was hoping I could do is implement my readObject to call readFields() and then ignore the "bad" attribute's stream data by not doing a get() on it. But readFields will throw ClassNotFoundException because the bad attribute's SUID doesn't match what is in the stream. I was hoping that check would have been deferred to the get() call, but from what I can glean in the doc, that isn't the case.


Is there a way to do this?


Thanks,

-- Dave

   <<Less

Re: Cleaning up bad stream data

Posted By:   Eric_Lindauer  
Posted On:   Sunday, August 18, 2002 07:35 PM

Hi Dave,



I believe your two step solution is the only way. This exact problem you are describing, by the way, is why Serialization is not suggested as a mechanism for long-term storage. It's really meant for temporary transport ( like between JVMs in a distributed application ).




You might, however, be able to do some craziness with ClassLoaders to make the two step process appear to happen in one step to the users. Use a special ClassLoader to load the old class, deserialize the object, and then convert it to kind of class-less form ( a string, an xml document, whatever ), then use this form, as you suggested, to create an instance of the new class ( using the System classloader ).




Hope this helps.

-Eric
About | Sitemap | Contact