FasterXML/jackson-module-kotlin

Field name conversion issues caused by automatic generation of getter functions in Kotlin

Closed this issue · 1 comments

A bug in which the name of the getter function is not generated as intended when compiling Kotlin due to the use of the field name as a getter function during serialization in Jackson, so that the field name conversion such as snake case is not converted to the desired format

Kotlin code example:

@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy::class)
data class ABC (
    val aBcDef: String,
)

internal class ObjectMapperTest {
    val mapper = ObjectMapper()

    @Test
    fun `test abc`() {
        val abc = ABC("John")
        println(mapper.writeValueAsString(abc))
    }
}

When the above code is executed, the aBcDef field should be converted to the a_bc_def field, but it is actually converted to abc_def

Result:

{"abc_def":"John"}

Kotlin Version : 1.9.0
Jackson Databind Version: 2.15.2
Jackson Module Kotlin Version: 2.15.2

A workaround option for these issues will be released in 2.16.
Please see the issue below for details.
#630

This issue is closed as a duplicate.