jackson-module-kotlin
jackson-module-kotlin copied to clipboard
After upgrading from 2.12.3 to 2.13.0, conversion fails in Kotlin
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
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.
It seems this is fixed by configuring the mapper with: .withGetterVisibility(JsonAutoDetect.Visibility.NONE)
.
Maybe an upgrade notice could be added?
(transferred since this appears to be Kotlin-related, wrt naming)
This issue will be fixed by #630 and therefore closed as a duplicate.