Fortunately, I'm actually writing this right now ... In addition to the benefits mentioned (and I'm not very good at what I don't understand), writing your own output format seems to have the following advantages:
- Allows the use of conditional output (various applications for serialization, such as saving and copying, can serialize various parts of an object).
- It should be faster, use less memory and in some cases use less disk than the default mechanism (this is from Bloch Effective Java 2).
- Allows you to rename variables in a serialized class, while maintaining backward compatibility.
- Allows you to access data from deleted fields in the new version (in other words, change the internal representation of your data while maintaining backward compatibility).
I saw the documentation you are quoting, and mentioning only these two options is a little misleading and leaves quite a bit: you can configure your serialization format in two ways, using the ObjectOutput / InputStream interface to write and read the fields in a specific order (described in Bloch) and use the PutField and GetField classes to write and read fields by name. You can use serialPersistentFields as a quote to extend this second method, but this is not required unless you need to read or write data with a name that is not the name of a member variable.
There is a third way to control the format using the Externizable interface, although I have not researched it yet. And some of the benefits can also be obtained through Serialization proxies (see Bloch).
Someone can correct me in detail if I missed something.
source share