Problem
In real life use cases (especially with libraries like Room), we often deal with nested/embedded objects.
For example:
data class AccountWithCurrencies(
@Embedded
val account: Account,
@Relation(
parentColumn = "id",
entityColumn = "accountId"
)
val currencies: List<AccountCurrency>
)
Currently, to map it into a DTO:
@KOMMMap(from = [AccountWithCurrencies::class])
data class AccountDto(
val name: String,
val currencies: List<AccountCurrencyDto>
) {
var id: Long = 0L
internal set
}
…we need to use two explicit converters:
@KOMMMap(from = [AccountWithCurrencies::class])
data class AccountDto(
@MapConvert<AccountWithCurrencies, AccountDto, NameConverter>(NameConverter::class, "account")
val name: String,
val currencies: List<AccountCurrencyDto>
) {
@MapConvert<AccountWithCurrencies, AccountDto, IdConverter>(IdConverter::class, "account")
var id: Long = 0L
internal set
}
Potential solution
Introduce an Embedded mapping feature.
This would allow specifying the source property once, so that multiple fields can be mapped from it.
Problem
In real life use cases (especially with libraries like Room), we often deal with nested/embedded objects.
For example:
Currently, to map it into a DTO:
…we need to use two explicit converters:
Potential solution
Introduce an
Embeddedmapping feature.This would allow specifying the source property once, so that multiple fields can be mapped from it.