Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Serialization - What is the advantage of using ObjectStreamField [] serialPersistentFields?

For class that implements Serializable interface there are 2 ways to define what specific fields get streamed during the serialization:

  1. By default all non-static, non-transient fields that implement Serializable are preserved.
  2. By definning 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?

like image 536
aviad Avatar asked Mar 11 '12 22:03

aviad


People also ask

What is the main purpose of Serialization in Java?

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.

What is Serialization and what is the use?

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.

What is serialization in Java stack overflow?

Serialization is the process of converting an object to a disk-storable format, for re-loading it at a later time.


1 Answers

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.

like image 56
user207421 Avatar answered Sep 21 '22 20:09

user207421