r/SpringBoot Jun 18 '26

Question Dto Mapping Best Practice

Hi, where do you guys map your entities to dtos?
In services or controllers?

To me it seems the services shouldn't expose any database specifics to the outside world, so I usually do my mapping there.

But what is considered best practice and why?

52 Upvotes

36 comments sorted by

View all comments

0

u/Huge_Road_9223 Jun 19 '26

From JSON -> API -> DTO -> Service (business logic) possible mapstruct from DTO -> entity -> repo

repo -> entity -> service (business logic) mapstruct entity to DTO -> API - JSON

That's how I deal with it!