Within a stream, the first reference to any object results in the object being serialized or externalized and the assignment of a handle for that object. Subsequent references to that object are encoded as the handle. Using object handles preserves sharing and circular references that occur naturally in object graphs. Subsequent references to an object use only the handle allowing a very compact representation.
Except for serializable fields, primitive data is written to the stream in block-data records, with each record prefixed by a marker and an indication of the number of bytes in the record.
- The above is from the Oracle Docs for Serialization. I am reading into Serialization to get a better and in-depth understanding, can someone please help me decode the highlighted parts in simple English. (I am looking for an answer in the context of how the stream is generated, especially when it talk about how the primitive data is being stored in the buffer)
Serialization is useful when we want to:
- Persist the state beyond the lifecycle of the JVM - file/db
- Send data over to another jvm based application over a network - data exchange
Doc: https://docs.oracle.com/javase/6/docs/platform/serialization/spec/serial-arch.html
- I have been working with Spring/Hibernate, and in none of the applications, the models are defined as type Serializable. The main reason to use Serializable is the version control for future enhancement, but without Serializable Hibernate persists the data in the DB/but serialization to a file using ObjectOutputStream fails. Can someone help me understand this, why does Hibernate not require entities to be of the type Serializable?