I am going through Effective Java, item 75:
If all instance fields are transient, it is technically permissible to dispense with invoking defaultWriteObject and defaultReadObject , but it is not recommended. Even if all instance fields are transient, invoking defaultWriteObject affects the serialized form, resulting in greatly enhanced flexibility. The resulting serialized form makes it possible to add nontransient instance fields in a later release while preserving backward and forward compatibility. If an instance is serialized in a later version and deserialized in an earlier version, the added fields will be ignored. Had the earlier version’s readObject method failed to invoke defaultReadObject , the deserialization would fail with a StreamCorruptedException
The question is why it's necessary to call defaultReadObject/defaultWriteObject to preserve backward and forward compatibility?
Can you explain with an example?
Why the added fields will be ignored?
Why a StreamCorruptedException will be thrown?