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

kotlin: Mapping from null property to object with default value #28

Open
brice-laurencin opened this issue Jan 29, 2025 · 0 comments
Open

Comments

@brice-laurencin
Copy link

Given this code:

    data class From (
        val nonNullProperty:String = "I'm not nullable",
        val nullProperty:String? = null
    )

    @NoArgsConstructor
    data class To(
        val nonNullProperty: String,
        val otherNonNullProperty: String = "I'm not nullable",
    )
    @Test
    fun rien() {

        val shapeshift = ShapeShiftBuilder().withMapping<From, To> {
            autoMap(AutoMappingStrategy.BY_NAME)
            From::nullProperty mappedTo To::otherNonNullProperty
        }.build()



        checkNotNull(shapeshift.map<From, To>(From()).otherNonNullProperty)
    }

I would assume that the resulting object had otherNonNullProperty with its default value, but it seems using the no-arg constructor from noArg kotlin plugin does not honor default values.

Any way to work around this? I'd rather not use an ObjectSupplier if that would be possible, this seems tedious and error-prone.

FYI, if all the members of To have a default value, it works fine.

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