I'm maintaining a large Java Spring Framework project and I have a question regarding best practices.
Is it OKAY to put annotation on DTO classes?
My DTOs (data transfer objects) are residing in a separate JAR commons module with its own pom.xml
file. My understanding of the commons module is that it should stay business logic free and should only retain the most basic dependencies.
Recently, I faced an issue where I have to tell Jackson what fields to (de)serialize to json. That is the easiest done using annotations. But that also means I have to include Jackson Json library into the commons module - which I may need to avoid for the sake of best practices and proper design.
@JsonInclude(Include.NON_NULL)
public class MyCustomDTO {
...
}
Is that okay to do? If not, what is the best practice?
A side question, how could I ignore some fields in the MyCustomDTO
without using annotations.I tried to move the annotation to my web service implementation class but that does not work.
Aucun commentaire:
Enregistrer un commentaire