question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:open
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
sudo-nan0-RaySKcommented, Mar 8, 2022

Same happening with Java as well.

0reactions
cowtowncodercommented, Mar 8, 2022

@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).

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found