Is there any best practices to create in Kotlin Ma...
# spring
l
Is there any best practices to create in Kotlin Mappers between Entities and DTOs and vice versa? Or any should I use mapper libraries like Dozer or MapStruct?
g
l
Hi @Gerard Klijs thanks for the link. What I actually meant is the conversion from and to Entities to DTOs in Kotlin. I know for example that one can use Dozer / MapStruct to convert from one data class to another. The question is more about if they are recommended or is there a better way to do it with Kotlin without using this libraries
g
Can't really help with that. Just use Java professionally, and often the data is so much different it needs weird tricks with MapStruct, so we often use a plain utils class for it. Maybe in Kotlin an extension would be the best way, so you could do something like foo.toBar()
j
Handfully crafted extension functions are the best, IMHO. I’ve always found that mappers just add complexity and bugs just to save a few lines of trivial, clean, refactorable code.
l
Thank you @jbnizet for you answer. Currently I am using transformation by hand. My colleague says e.g. that we should use Extension Functions only for code we are not owning. I think we should also use Extension Functions also on our own code for e.g. creating transformation between data classes. Do you have any information about if there is a rule saying that it is a bad idea on using extension functions for owned code?