adam bien's blog
A Note on Data Transfer Objects (DTO)s 📎
- Data Transfer Objects (DTOs) are introduced to decouple (JPA) entities from the UI
- DTOs are also motivated by their typesafe nature
- Lacking typesafety, JSON-P JsonObjects are not used as DTOs
- Most DTOs are exposed as HTTP/JSON
- Often 3rd party libraries are used to map a DTO into a JSON
- Sometimes DTOs are called Value Objects
- The vast majority of DTOs remains identical to entities over the entire lifecycle of a project
- Copying data between DTOs and entities requires series of getter-setter invocations
- DTOs are growing, the mapping logic is extracted into dedicated "mappers"
- DTOs and mappers introduce a significant amount of untested code, which disturbs the code coverage statistics
- Getters and setters, constructor tests are written to increase the code coverage
- Now: structural JPA entity code changes, affect DTOs, mappers and the corresponding unit tests
See you at Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting. Is Munich's airport too far? Learn from home: airhacks.io.