Removing either Serializable or Externalizable is an incompatible change since when written it will no longer supply the fields needed by older versions of the class.Changing a class from a non-enum type to an enum type or vice versa since the stream will contain data that is incompatible with the implementation of the available class.Changing a class from Serializable to Externalizable or vice-versa is an incompatible change since the stream will contain data that is incompatible with the implementation of the available class.The default field data must consistently either appear or not appear in the stream. Changing the writeObject or readObject method so that it no longer writes or reads the default field data or changing it so that it attempts to write it or read it when the previous version did not.Earlier versions of the class attempting to read the field will fail because the type of the data in the stream does not match the type of the field. Changing the declared type of a primitive field – Each version of the class writes the data with its declared type.As when deleting a field, the field of the earlier version will be initialized to the default value, which can cause the class to fail in unexpected ways. This version of the class will not write that data to the stream, so it will not be available to be read by earlier versions of the class. Changing a non-static field to static or a non-transient field to transient – When relying on default serialization, this change is equivalent to deleting a field from the class.Moving classes up or down the hierarchy – This cannot be allowed since the data in the stream appears in the wrong sequence.However, this default value may adversely impair the ability of the earlier version to fulfill its contract. When the stream is read by an earlier class, the value of the field will be set to the default value because no value is available in the stream. Deleting fields – If a field is deleted in a class, the stream written will not contain its value.The incompatible changes that may occur while evolving a class are given below (considering default serialization or deserialization): Incompatible changes to classes are those changes for which the guarantee of interoperability cannot be maintained. Serialization and deserialization example 1. Sample class following serialization best practicesħ.
Java serialization incompatible changesĤ. Now, even if you use both in the application classes, do you know what can break your design even now? Lets identify the future changes in the class which will be compatible changes and others which will prove incompatible changes. This interface recommends us to use serialVersioUID also. Java Serializable interface guarantees the ability to serialize the objects. Serialization in Java is achieved with Serializable interface. Java serialization enables writing Java objects to file system for permanent storage or on network to transfer to other applications.