After that, I deserialize the object from file to a MyClass object using the changed code. Is it OK? Will there any exception thrown during deserialization? I want to reuse the old object. I.e. I want the de-serializing can be done. So I hope there is no exception thrown.

3 Answers
3

No, on the contrary, you'll run into great problems. In Joshua Bloch's Effective Java, Item 74, he notes to implement Serializable judiciously, as it decreases the flexibility to change a class's implementation once its been released.

He specifically notes that "If you do not make the effort to design a custom serializable form, but merely accept the default, the serialized form will be forever tied to the class's original internal representation."

I want to reuse the old object. I.e. I want the de-serializing can be done. That's the reason I will use the same serialVersionUID.
–
KaiSep 21 '10 at 1:21

1

It will blow up. You can keep the old version of the class, and make a new version with a new name... then have the new version use a constructor to map values from old class to new class...
–
bwawokSep 21 '10 at 2:07