For class that implements Serializable
interface there are 2 ways to define what specific fields get streamed during the serialization:
Serializable
are preserved.ObjectStreamField [] serialPersistentFields
and explicitly declaring the specific fields saved.I wonder, what is the advantage of the second method except for the ability to define specific fields order?
Serialization in Java is the concept of representing an object's state as a byte stream. The byte stream has all the information about the object. Usually used in Hibernate, JMS, JPA, and EJB, serialization in Java helps transport the code from one JVM to another and then de-serialize it there.
Serialization is the process of converting a data object—a combination of code and data represented within a region of data storage—into a series of bytes that saves the state of the object in an easily transmittable form.
Serialization is the process of converting an object to a disk-storable format, for re-loading it at a later time.
The 'advantage' is that it does what it says in the Javadoc: defines which fields are serialized. Without it, all non-transient non-static fields are serialized. Your choice.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With