The most challenging task is to change the structure of a class when a new
field is added or removed. As per the specifications of Java Serialization,
addition of any method or field is considered to be a compatible change whereas
changing of class hierarchy or non-implementation of Serializable interface is
considered to be a non-compatible change.
Some Simple Examples of compatible changes are:
1 Addition of a new field or class will not affect serialization, since any new
data in the stream is simply ignored by older versions. the newly added field
will be set to its default values when the object of an older version of the
class is un marshaled.
2 The access modifiers change (like private, public, protected or default) is
compatible since they are not reflected in the serialized object stream.
3 Changing a transient field to a non-transient field is compatible change since
it is similar to adding a field.
4 Changing a static field to a non-static field is compatible change since it is
also similar to adding a field.
Some Simple Examples of incompatible changes are:
1 Changing implementation from Serializable to Externalizable interface can not
be done since this will result in the creation of an incompatible object stream.
2 Deleting a existing Serializable fields will cause a problem.
3 Changing a non-transient field to a transient field is incompatible change
since it is similar to deleting a field.
4 Changing a non-static field to a static field is incompatible change since it
is also similar to deleting a field.
5 Changing the type of a attribute within a class would be incompatible, since
this would cause a failure when attempting to read and convert the original
field into the new field.
6 Changing the package of class is incompatible. Since the fully-qualified class
name is written as part of the object byte stream.