> Is there any way to write code to read the multiple old versions, which
> differ ONLY in serialVersionUID? Basically, I'd really love a subclass of
> ObjectInputStream that just doesn't look at this field in objects it reads.
The quickest hack would be to do a search and replace on the data.
I guess you can probably override ObjectStreamClass.readClassDescriptor.
If you call the super on that method, then it will call
ObjectStreamClass.readUTF for the class name, followed by
ObjectStreamClass.readLong. That does rely on implementation specific
details. You could read the data yourself (format is in the specs) and
just return a value from ObjectStreamClass.lookup, or from another
ObjectStreamClass.
Another alternative would be to use ClassLoaders to have two copies of
the class involved. In this case any instance of one class would not be
an instance of the other, so you would have to copy the data across
(probably via an intermediary, as no class can link to both of the
serialisable classes).
Tom Hawtin
Mark Rafn - 02 Apr 2007 00:30 GMT
>> Is there any way to write code to read the multiple old versions, which
>> differ ONLY in serialVersionUID? Basically, I'd really love a subclass of
>> ObjectInputStream that just doesn't look at this field in objects it reads.
>The quickest hack would be to do a search and replace on the data.
I was afraid someone would suggest that. I guess I could subclass
ObjectInputStream so that it uses a private FilterInputStream which does
nothing but fixup serialVersionUID in the bytestream. Ick.
>I guess you can probably override ObjectStreamClass.readClassDescriptor.
That's promising. I'll see how that goes.
>Another alternative would be to use ClassLoaders to have two copies of
>the class involved.
No good for me. Once in memory, I'm going to want to pass these around
normally, and having multiple distinct same-named classes gets very hairy.
Thanks for the ideas!
--
Mark Rafn dagon@dagon.net <http://www.dagon.net/>