Skip to content

data class constructor not used for deserialization since 2.18.x #919

@huberchrigu

Description

@huberchrigu

Search before asking

  • I searched in the issues and found nothing similar.
  • I have confirmed that the same problem is not reproduced if I exclude the KotlinModule.
  • I searched in the issues of databind and other modules used and found nothing similar.
  • I have confirmed that the problem does not reproduce in Java and only occurs when using Kotlin and KotlinModule.

Describe the bug

I have many data classes with a single argument constructor that was used for deserialization previous to 2.18.x. Now it is used only if I add a @JsonCreator annotation explicitly.

To Reproduce

The following test fails since Jackson 2.18.x, but worked with 2.17.x:

class VersionJsonTest {
    @Test
    fun `should deserialize`() {
        val objectMapper = ObjectMapper().registerModule(KotlinModule.Builder().build())
        assertThat(objectMapper.readValue("\"1.0.0\"", Version::class.java)).isNotNull
    }

    data class Version(private val value: String)
}

Expected behavior

Deserialization should still work after a minor upgrade.

Versions

Kotlin: 1.9.25
Jackson-module-kotlin: 2.18.1-2.18.3
Jackson-databind: 2.18.1-2.18.3

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions