You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug @JsonProperty is ignored sometimes depending on the name of the property.
data class Works(
@JsonProperty("AbCdE")
val abc: String
)
data class Broken1(
@JsonProperty("AbCdE")
val ABC: String
)
data class Broken2(
@JsonProperty("AbCdE")
val aBC: String
)
fun main() {
val om = jacksonObjectMapper()
println(om.writeValueAsString(Works("test")))
// {"AbCdE":"test"}
println(om.writeValueAsString(Broken1("test")))
// {"abc":"test"}
println(om.writeValueAsString(Broken2("test")))
// {"abc":"test"}
}
To Reproduce
See code above.
Expected behavior
All examples serialize to {"AbCdE":"test"}.
@fellmann
First, annotating the getter eliminates this problem.
importcom.fasterxml.jackson.annotation.JsonPropertydata classWorks(
@get:JsonProperty("AbCdE")
valabc:String
)
data classBroken1(
@get:JsonProperty("AbCdE")
valABC:String
)
data classBroken2(
@get:JsonProperty("AbCdE")
valaBC:String
)
The root cause is that the name of the getter in the JVM takes precedence, resulting in a discrepancy between the property name and the parameter name on Jackson and a failure to tie the annotation together.
This problem can be resolved by implementing #630.
Describe the bug
@JsonProperty
is ignored sometimes depending on the name of the property.To Reproduce
See code above.
Expected behavior
All examples serialize to
{"AbCdE":"test"}
.Versions
Kotlin: 1.7.20
Jackson-module-kotlin: 2.13.4
Jackson-databind: 2.13.4.2
The text was updated successfully, but these errors were encountered: