I've seen a lot of questions on how to Serialize POJO's in java using different frameworks, but I wanted to really understand the need of making our POJO's Serializable in the first place. You use JavaScript to handle the POJO objects or Spring or any other framework - why is it that we always have to make our POJO's Serializable
?
Is it something that has to be done on a GOOD PRACTICE or a BEST PRACTICE?
If it is not the case, what is the advantage that we would be able to leverage by Serializing POJO classes?
There are a couple of threads that discuss about this, but I'm not really satisfied with the explanation / answers!
Can anyone here, shed some light on this concept please?
You serialize POJO's when you usually need to:
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.
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