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

After upgrading from 2.12.3 to 2.13.0, conversion fails in Kotlin #504

Closed
MrBuddyCasino opened this issue Aug 14, 2021 · 4 comments
Closed

Comments

@MrBuddyCasino
Copy link

MrBuddyCasino commented Aug 14, 2021

Describe the bug
A conversion that worked before doesn't anymore: Conflicting getter definitions for property "fSRI": com.example.ModelRow#getFSRI-SECTION() vs com.example.ModelRow#getFSRI-ID()

Version information
upgrade from 2.12.3 to 2.13.0

To Reproduce

import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.MapperFeature
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
import com.fasterxml.jackson.module.kotlin.KotlinModule
import com.fasterxml.jackson.module.kotlin.convertValue
import org.junit.jupiter.api.Test

class JacksonTest {

    @Test
    fun doTest() {
        val map = mapOf( "FSRI-SECTION" to "1", "FSRI-ID" to "1234")
        objectMapper().convertValue<MyModel>(map)
    }

    data class MyModel(
        val `FSRI-ID`: String?,
        val `FSRI-SECTION`: Int?
    )

    private fun objectMapper(): ObjectMapper {
        // defaults largely as specified in Jackson2ObjectMapperBuilder
        return ObjectMapper()
            .registerModule(KotlinModule(nullToEmptyCollection = true, nullIsSameAsDefault = true))
            .registerModule(JavaTimeModule())
            .registerModule(Jdk8Module())
            .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
            .configure(MapperFeature.DEFAULT_VIEW_INCLUSION, false)
    }

}

Expected behavior
Conversion should succeed.

Additional context
Kotlin version: 1.5.21

@MrBuddyCasino
Copy link
Author

After some debugging, Jackson seems to pick up a 3rd fSRI property via findImplicitPropertyName() called in _addGetterMethod(), which then leads to the exception. I'll check if I can disable that behaviour.

@MrBuddyCasino
Copy link
Author

It seems this is fixed by configuring the mapper with: .withGetterVisibility(JsonAutoDetect.Visibility.NONE).
Maybe an upgrade notice could be added?

@cowtowncoder cowtowncoder transferred this issue from FasterXML/jackson-databind Sep 28, 2021
@cowtowncoder
Copy link
Member

(transferred since this appears to be Kotlin-related, wrt naming)

@cowtowncoder cowtowncoder changed the title After upgrading from 2.12.3 to 2.13.3, conversion fails in Kotlin After upgrading from 2.12.3 to 2.13.0, conversion fails in Kotlin Oct 21, 2021
@k163377
Copy link
Contributor

k163377 commented Mar 4, 2023

This issue will be fixed by #630 and therefore closed as a duplicate.

@k163377 k163377 closed this as completed Mar 4, 2023
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

3 participants