Why should we do POJO Serializable in Java?

I saw a lot of questions about how to serialize POJOs in java using different frameworks, but I really wanted to understand the need to make our POJO Serializable in the first place. You use JavaScript to process POJOs or Spring or any other frameworks - why should we always do POJOs Serializable?

Is this something that needs to be done in GOOD PRACTICE or BEST PRACTICE ?

If this is not the case, what is the advantage we could take by serializing the POJO classes?

There are several topics that discuss this, but I'm not very happy with the explanation / answers!

Can anyone shed light on this concept here?

+4
source share
1 answer

Serialize your POJO when you usually need to:

  • Transfer them through some medium (web service, etc.).
  • Store them on some medium. (This, in turn, is related to how you are going to store them: XML, binary, etc.).

You do not always have to serialize them, it depends on what you do.

For example, if you have a web application with the concept of an object Userin which the user has a username, and perhaps some settings may not make sense to make this serializable class. However, if you open a web service through which third parties can retrieve user information, then this class must be serializable so that it can be passed to third parties.

+10
source

Source: https://habr.com/ru/post/1609601/


All Articles