Hi folks. What are your best practices to map data classes to other data classes?
For example we have multiple layers in our ktor application (requests/responses, DTOs, entities...) and this is always a lot of boilerplate code to map classes (even with extension functions)
Is there some state of the art for it?
Be careful with using annotations and string-references to achieve this! You loose a lot of refactorability when picking such a solution. The ShapeShift lib allows you to do it w/o these perils, buttt aws you see it is not much shorter than manuall implementing a
toXYZ()
or
fromXZY()
methods when needed.
✅ 2
👍 2
a
andriyo
12/16/2023, 12:32 AM
i find it easier just to implement mapping extension functions. It's "in your face", honest code, no black magic, easy to refactor if needed. It's boiler-plate-ly, of course, but if you use something like Copilot, it's usually one Tab press to write