How to deserialize an object persisted in a db now when the object has different serialVersionUID

后端 未结 6 1954
太阳男子
太阳男子 2020-12-14 04:34

My client has an oracle data base and an object was persisted as a blob field via objOutStream.writeObject, the object now has a different serialVersionUID (eve

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-14 05:04

    Bit of a hack perhaps, but might be helpful to someone: I had a similar problem, which I solved by duplicating the offending class and settings the new class UID to 0L (for example). Then in the code which does the serialisation I copied the original object into the new object and serialised out. Then you can update your code, and deserialisation code, to use the new class in place of the old. This works perfectly, although you are stuck with the new class name. You can repeat the process, however, to recover your old class name. At the end of it, you have a fixed UID of your choosing. Tip I learned the hard way: always set your own UID !

提交回复
热议问题