https://kotlinlang.org logo
Title
s

spaisey

07/26/2018, 7:05 AM
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

Gokul

07/26/2018, 7:07 AM
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

spaisey

07/26/2018, 7:09 AM
Just edited above.... don't put the extension function in the Person class, then it doesn't pollute the class.
👍 2
g

Gokul

07/26/2018, 11:24 PM
Thanks Scott.