Why should we make our POJO's Serializable in Java?
You serialize POJO's when you usually need to:
- Transmit them through some medium (Web Service, etc)
- Store them on some medium. (This in turn devolves into how you are going to store them: XML, binary, etc).
You do not always have to serialize them, it depends on what ever it is you are doing.
For instance, if you have a web application with the concept of a User
object, wherein a user has a user name, and maybe some preferences it might not make sense to make that class serializable. However, if you expose a web service through which 3rd parties can extract user information, then that class would need to be serializable so that it can be transmitted to said 3rd parties.
Serialization is needed when you have to convert the Object to byte Stream.
Byte Streaming is needed when you transmit the object with other applications or when you have to store that object.
So if you are using other formats like JSON for passing data, you won't need to serialize your objects.