简体   繁体   中英

Why do most of the classes of Java frameworks extend serializable interface?

Serialization is technique where we send convert objects into byte code for sending it over the network. Now, a lot of classes of Java frameworks(Spring, hibernate(SessionFactory) et. al) extend serializable interface? Why is that so?

Why searching on the web I found this piece of text "Serialized classes can support coherent versioning and flexible enough to allow gradual evolution of your application object schema".

Is this the correct answer of question above? If yes kindly explain it, if not then what's the actual cause of classes extending serialable interface

I think you can see this as a mean of precaution : having your classes being serializable from the beginning doesn't cost you much.

But adding that later to your code has the potential of being way more expensive.

Beyond that: making your classes serializable actually forces you to think/consider such "aspects" when creating your class. Thus it can help to improve the quality of your design - because you don't forget about that aspect.

One possible reason is that web containers may store session data on disk if needed (eg high server load and session is inactive for some time). For that to work, all data stored in session (transitively, ie all instances referenced directly or indirectly by session data) must be serializable.

Additionally to any data you're storing in session, many frameworks store some data in session as well (session-scoped beans, as a Spring-related example).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM