Adding / modifying / deleting public or protected fields or methods for a class will affect its ability to deserialize. Like adding interfaces. They are used, among other things, to generate a serialVersionUID , which is written to the stream as part of the serialization process. If the serialVersionUID class does not match the loaded class during deserialization, it will fail.
If you explicitly set serialVersionUID in your class definition, you can do it. You might want to implement readObject and writeObject .
In extreme cases, you can implement Externalizable and have full control over the entire serialization of the object.
The absolute worst case scenario (albeit incredibly useful in some situations) is to implement writeReplace on a complex object to replace it with a kind of simpler value object in serialization. Then, when deserializing, an object with a simpler value can implement readResolve to either rebuild or find a complex object on the other hand. It's rare when you need to pull it out, but it's terribly fun when you do it.
David blevins
source share