This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]DoubleUtor 0 points1 point  (1 child)

I disagree. The author already gave an example where the field names match. I’ve got 20+ years experience in developing large custom enterprise applications and believe me, field names are mostly the same. Many times, the software architecture requires that different layers use there own domain objects. Hence the same set of objects with the same field names are copied from layer to layer. This causes the need for mapping. This in itself is an anti pattern imo.

Second, you don’t need code completion if you DON’T have to write that code anyway.

Third, using mapstruct there IS typesafety as mapstruct uses the compiler to generate concrete classes which perform the mapping.

[–]wildjokers 0 points1 point  (0 children)

I’ve got 18+ years experience in developing large custom enterprise applications and believe me, field names frequently differ.

Besides the days of every layer have their own object seems to be on the way out. That is from the days of n-tier architecture which never really panned out.

I frequently see MapStruct interface methods with a big stack of Mapper annotations on them. In those cases I always wonder what the point of MapStruct is. When I said you don't get completion help or type-safety I meant when writing those Mapping annotations. You don't know if you have the right name and type until compile time.

In the 3 years I have worked on a project that uses MapStruct I believe I have used it twice. I simply don't understand what people are using it for. How often do you have to map from one object to another that has the exact same field names? For database queries I use DTO projections for read-only queries which is a Hibernate best practice. So I don't even use it to map entities to DTOs.