Hi <@UBFKYLZA9> - I would use an Extension on the ...
# server
s
Hi @Gokul - I would use an Extension on the Entity object to convert to DTO ....
fun Person.toDto() = PersonDto("${firstName}  ${lastName}")
. You can then call person.toDto(). The Extension function lives outside the Person class (say, in Extensions.kt) in the same package as the DTO class.
g
Yeah, I started off that way but it felt weird that the
entity
had to know details of the
DTO
. So i finally moved that logic to a mapper that does the required mapping between them.
s
Just edited above.... don't put the extension function in the Person class, then it doesn't pollute the class.
👍 2
g
Thanks Scott.