Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No mapping done with autoMap and provided object instance #27

Open
jwaibel-pons opened this issue Jun 11, 2024 · 0 comments
Open

No mapping done with autoMap and provided object instance #27

jwaibel-pons opened this issue Jun 11, 2024 · 0 comments

Comments

@jwaibel-pons
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant