dcsimg
How to determine whether we should make our Data Transfer Objects serializable
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   saladin_sharif
Posted On:   Wednesday, January 31, 2007 03:44 PM

Hi, I am creating Data Transfer Objects (Value Objects) to store and retrieve data from tables in the database. I already know that classes that need to be serialized should be declared to implement the java.io.Serializable interface. But I am only probabley going to need to use my DTOs for retrieving data from the database and transfering data between classes within my application. I don't think my DTOs would need to be serialized. Should I declare them to be Serializable just to be on the safe side? Is there any draw back or disadvantage to declaring a class to be Serializable when it doesn't need to be Serializable?? Thanks.    More>>

Hi,


I am creating Data Transfer Objects (Value Objects) to store and retrieve data from tables in the database. I already know that classes that need to be serialized should be declared to implement the java.io.Serializable interface. But I am only probabley going to need to use my DTOs for retrieving data from the database and transfering data between classes within my application.


I don't think my DTOs would need to be serialized. Should I declare them to be Serializable just to be on the safe side? Is there any draw back or disadvantage to declaring a class to be Serializable when it doesn't need to be Serializable??


Thanks.

   <<Less

Re: How to determine whether we should make our Data Transfer Objects serializable

Posted By:   Christopher_Koenigsberg  
Posted On:   Friday, February 2, 2007 11:51 PM

No disadvantage that I know of. In fact it might be an advantage sometime in the future, if you start doing something where they do need to be Serializable.



For example, if you set them as attributes in session scope, in a web application, they are supposed to be Serializable.



Some servlet containers will throw a nasty exception on your web application, if you try to set non-serializable objects in session scope... especially if they are clustered where a session may get replicated between multiple servers, because all the attributes get serialized and de-serialized along the way, in this replication.... or persistence, too, if the servlet container does something to persist its session scope attributes to backing storage, it might need to serialize them then too.
About | Sitemap | Contact