Skip to content

No mapping done with autoMap and provided object instance #27

Description

@jwaibel-pons

I'm using shapeshift 0.9.0. Not sure if this a bug or I'm just misunderstanding the documentation.

I have a Src class which is provided and can't be changed (so it's not possible to add annotations there).

I'd like to map this class to my Dest class. I'd like to use auto mapping, because I'm lazy :-), and I have to provide an object instance, because the Dest class lacks an empty constructor. Adding an empty constructor with the no-args plugin should be avoided if possible.

This is my example code:

data class Src(
    val id: String,
    val name: String,
    val telephone: String,
)

data class Dest(
    val id: String,
    val name: String,
    val telephone: String,
)

fun main(args: Array<String>) {
    val src = Src("42", "Dr Dolittle", "123456789")

    val mapper = mapper<Src, Dest> { autoMap(AutoMappingStrategy.BY_NAME_AND_TYPE) }
    val shapeShift = ShapeShiftBuilder().withMapping<Src, Dest> { mapper.mappingDefinition }.build()

    val destTemplate = Dest("fake", "fake", "fake")
    val dest = shapeShift.map(src, destTemplate)

    println(dest)
}

But, when running this, dest is only the provided "fake" class, and no values from Src have been mapped.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions