Hi folks. What are your best practices to map data...
# server
l
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?
c
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
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
👍 4