In a recent Web based Java project, I have come across various places where I have seen a Spring based Controller/Component implementing Serializable.
I am curious, as to why a Controller/Component should have to implement Serializable?
I think it is wrong practice to do so and searching so far for any scenario to implement Serializable has not yielded anything. I think it violates MVC principle and is unconventional. You would want to keep Domain/Business Objects separate from Controllers/Components.
I would like to correct this bad practice in the code base but just wanted to ensure I have a reason to do so.
Any explanation/scenario illustrating this case will be appreciated.
There's no need for controllers to be Serializable. They're stateless and just mediate between the model and the view. The same could be said for other stateless components. There's no benefit in making them Serializable.
Stateful model objects, however, are often Serializable because they're sometimes placed in HttpSession. App servers require objects in session to be Serializable for replication and persistence purposes.
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