问题
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