DTO implementation of Serializable interface

两盒软妹~` 提交于 2019-12-08 06:09:31

问题


Is it mandatory to implement Serialize for Java DTO/Model objects? If so why? If not whats the impact on performance etc?


回答1:


A DTO is normally a Data Transfer Object. It doesn't have to use Java Serialization, but if it doesn't it needs to follow some other convention.

Its not a matter of performance as if you are using Java Serialization it most likely has to be Serializable (or Externalizable which is still Serializable)




回答2:


Not if you're not saving them to a file or sending them across a socket. There's nothing about a DTO that requires serialization. The need for serialization will depend on your planned usage. DTOs are generally created from a row in a result set returned by a database query. They are then passed back as the return value from a DAO call. From there they can be decorated or used as-is and consumed in whatever way your application requires. There's no requirement for them to be serializable.




回答3:


DTOs are anemic in general and do not contain any business logic. DTOs are often java.io.Serializable - its only needed if you are going to transfer the data across JVMs.



来源:https://stackoverflow.com/questions/11833473/dto-implementation-of-serializable-interface

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!