I try to understand Serializable interface and it's utility.
I know now that objects that implement Serializable will be converted to Byte stream so they could be transferred over the network or persisted in database.
My question is why org.springframework.http.ResponseEntity doesn't implements Serializable interface since ResponseEntity is the spring RestController response?
PS: I ask the question and I know that maybe I am totaly missing the point and that I do not yet understand the concept Srializable and ResponseEntity.
java.io.Serializable uses a specific kind of serialization known as Java serialization. It was a major innovation when it was introduced as part of the core language platform (and still has some respectable features, like handling reference cycles), but it has some serious disadvantages, the biggest of which is that it's not compatible with other platforms (including the human eyeball).
Instead, modern applications tend to use other serialization mechanisms (primarily JSON, still plenty of XML, and some other options like Avro and Protocol Buffers). These don't use the built-in platform serialization features and instead use a library (such as Jackson) that inspects the objects and outputs the serialized form. This means that such objects have no need of implementing Serializable.
One major reason that ResponseEntity doesn't implement Serializable is that doing so requires all of its contents to also implement Serializable, or a surprise NotSerializableException can happen at runtime. Since there's no useful value, it's better to skip it.
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