ObjectMapper serialization for boolean fields named isFieldName changed between versions 2.10.5 and 2.12.4
See original GitHub issue(NOTE: transferred from “jackson-databind”, assumed Kotlin-module specific)
Describe the bug
I’m upgrading a project from Jackson 2.10.5 to 2.12.4 and one of the classes started serializing differently. The class has a field named isOpen
which is not a boolean. In 2.10.5 this serialized as "isOpen": { }
In 2.12.4 the field is dropped entirely.
Version information 2.12.4
To Reproduce
This first test passes with Jackson 2.10.5 and fails in 2.12.4. The second test passes in both versions.
class JacksonTest {
@Test
fun `will serialize a data class with a property named isOpen if it is not a boolean`() {
data class Thing(val isOpen: Map<String, Boolean>)
val data = Thing(isOpen = mapOf(Pair("a", true)))
ObjectMapper().writeValueAsString(data) shouldBe """{"isOpen":{"a":true}}"""
}
@Test
fun `will serialize a data class with a property named isOpen if it is a boolean`() {
data class Thing(val isOpen: Boolean)
val data = Thing(isOpen = true)
ObjectMapper().writeValueAsString(data) shouldBe """{"open":true}"""
}
}
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Jackson renames primitive boolean field by removing 'is'
A simple solution to changing the name that Jackson will use for when serializing to JSON is to use the @JsonProperty annotation, so...
Read more >ObjectMapper (jackson-databind 2.12.4 API) - javadoc.io
Versioned, Serializable. ObjectMapper provides functionality for reading and writing JSON, either to and from basic POJOs (Plain Old Java Objects), ...
Read more >Jackson 2.12 Features - cowtowncoder - Medium
Jackson 2.12.0 was just released on November 29, 2020. It is another “minor” version — meaning that it should be fully backwards-compatible ...
Read more >Serialize and Deserialize Booleans as Integers With Jackson
Learn how to serialize Boolean values into integers and numeric strings ... As we notice in our JSON output, our Boolean fields —...
Read more >com.fasterxml.jackson.core » jackson-databind
Version, Vulnerabilities, Repository, Usages, Date. 2.14.x. 2.14.1 · Central ... Aug 27, 2021. 2.12.4 · 3 vulnerabilities · Central · 1,496. Jul 06,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Same happening with Java as well.
@sudo-nan0-RaySK I don’t think this should be the case, unless Kotlin module is registered. If it does occur, this would belong here, but for now I assume it is Kotlin-MODULE specific (not necessarily language/value however; but module does not discriminate).