Hacker News new | ask | show | jobs
by lf-non 1253 days ago
They are incredibly useful when you need to rely on code-generators or need to deal with multiple type-systems. In our case row types were derived from database schema and api layer DTOs were derived from Protobuf schemas (neither were owned by our team) - it was convenient to have something (in our case MapStruct) to map between them.

Yes, they don't handle 100% cases and in many cases we need to write custom mappers, but for the 80% cases it does work it really eliminates a lot of tedious manual code. This is specially important if your codebase is evolving fast and domain model goes through multiple iterations.

Also, something that is often overlooked is that mappers are composable. So you could define a custom mapper for a specific class that needs special conversion, and then have MapStruct configured to use it in all the twenty classes that use that type without having to write those twenty mappers yourself. Its a big win.