Kotlin support

449 views
Skip to first unread message

Mateusz Nakielski

unread,
Aug 16, 2018, 5:59:47 AM8/16/18
to modelmapper
Hi,
I can't deal with using ModelMapper with data class in kotlin. Is there any solution for this problem. Or is it plannaed to make support for kotlin?

Mateusz Nakielski

unread,
Aug 16, 2018, 6:01:42 AM8/16/18
to modelmapper
Problem is, that when I use map function for two data classes, I get empty class(after invoke no args constructor, which I had to make, without it I got exception)

Nathan

unread,
Aug 16, 2018, 5:56:24 PM8/16/18
to modelmapper
Hi Mateusz,

I haven't tried using model mapper in Kotlin, but I've found this stack overflow post https://stackoverflow.com/questions/39199426/better-way-to-map-kotlin-data-objects-to-data-objects

The highest rated response suggests some alternative ways without model mapper that you might like to try. Personally I like the first approach by setting explicit mapping via a toPersonRecord function. This doesn't work if you want to do implicit mapping though.

If you're really intent on implicit mapping via model mapper there is an answer that shows what is needed to get it to work. https://stackoverflow.com/a/51640371 You lose pretty much all of the benefits of a data class by doing this though.

In terms of support in model mapper though I don't think you'll see it any time soon. https://github.com/modelmapper/modelmapper/issues/256

Cheers,
Nathan

Mateusz Nakielski

unread,
Aug 17, 2018, 4:16:15 AM8/17/18
to model...@googlegroups.com
Thank you for your answer!

Of course the first approach is the simpliest, but I like auto-transform fields with the same name. It is useful for entity and dto classes. If I have a lot of classes, making a transform function for every one is laborious. Unfortunately if I want to use data classes, it is necessarily, or I have to find another mapper tools.

Cheers

--
You received this message because you are subscribed to the Google Groups "modelmapper" group.
To unsubscribe from this group and stop receiving emails from it, send an email to modelmapper...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Serdecznie pozdrawiam,
życząc miłego dnia.
Mateusz Nakielski
Reply all
Reply to author
Forward
0 new messages