Closed mkowol-n closed 1 year ago
I guess the question is - is the iterable mapping available as a method in @Konverter
interface or does it work only for lists inside the mapped objects themselves?
Konvert can map Iterables, but not in the @Konverter
itself.
You can workaround this in several ways for now:
data class Match(val homeTeam: String, val guestTeam: String)
data class MatchDto(val homeTeam: String, val guestTeam: String)
data class MatchPlan(val matches: List<Match>)
data class MatchPlanDto(val matches: List<MatchDto>)
@Konverter
interface Mapper {
fun toDto(domain: Match): MatchDto
fun toDto(domain: MatchPlan): MatchPlanDto
}
@Konverter
interface Mapper {
fun toDto(domain: SomeClassTwo): SomeClassOne
fun toDto(domain: List<SomeClassTwo>) = domain.map { toDto(it) }
}
Oh, that makes sense. It would be nice feature for the future releases though :)
I implemented this, so the next version of Konvert will work as expected :+1:
Released with https://github.com/mcarleio/konvert/releases/tag/v2.3.0 Please try it out and report back if anything is not working as expected
Hi, I'm trying to map list of object and i'm getting an error.
Model I'm trying to map:
to:
I'm using interface with @Konverter annotation:
Thanks for help!