I've been reading a bit about the DTO pattern lately. I understand its purpose; isolating internals and creating contracts for the client. However, I've been thinking a lot about how to map them to entities, efficiently.
So, let's say I have 2 Dtos; CreatePostDto and ReadPostDto which may vary in several fields. Now, I want to map them to a PostEntity, which can be done using technologies like modelmapper, mapstruct, etc. However, mapping them in the service layer doesn't seem very appealing to me as the code tends to get messy.
One way is creating a generic mapper abstract class and provide implementations for specific dtos. Nevertheless, I'm sceptical of this approach as I may have many dtos i.e many postDtos and this results to many mapper classes.
Is there a better way to do this?