Skip to content

Allow nested properties as sources #210

Description

@syh7

I would like support for nested properties as sources. For example

data class Computer (
    val name : String,
    val info : Info,
)
data class Info (
    val ean: String,
    val buyDate: Instant,
)

data class ComputerDto(
    val name: String,
    val ean: String
)

@Konverter
interface ComputerMapper{
    @Konvert(mappings = [
        Mapping(target = "ean", source = "info.ean")
    ])
    fun toDto(source: Computer): ComputerDto
}

The trick is in Mapping(target = "ean", source = "info.ean"). I've often wanted to get a specific property from one of the subproperties, and right now I have a workaround of creating an extra function, like:

@Konverter
interface ComputerMapper {

    @Konvert(
        mappings = [
            Mapping(target = "ean", source = "info"),
        ],
    )
    fun toDto(source: Computer): ComputerDto
    
    fun mapEan(source: Info)=source.ean
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestopen for PRFeel free to create a PR

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions