Skip to content

Embedded feature #29

@Scogun

Description

@Scogun

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.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions