Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serialization of isXXX fields changed in 2.10.1, adding is prefix which was previously absent #346

Closed
LichKing-lee opened this issue May 28, 2020 · 5 comments
Labels

Comments

@LichKing-lee
Copy link

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
failure on jackson-module-kotlin 2.10.1 or higher

class JacksonTest {
    private lateinit var objectMapper: ObjectMapper

    @BeforeEach
    fun setUp() {
        objectMapper = jacksonObjectMapper()
    }

    @Test
    fun json() {
        val p = Person(32, "changyong", true)
        val json = objectMapper.writeValueAsString(p)

        val expected = """
            {"age":32,"name":"changyong","junior":true}
        """.trimIndent()

        assertThat(json).isEqualTo(expected)
    }
}

This result is {"age":32,"name":"changyong","isJunior":true}

Expected behavior
pass on jackson-module-kotlin 2.10.0 or lower

class JacksonTest {
    private lateinit var objectMapper: ObjectMapper

    @BeforeEach
    fun setUp() {
        objectMapper = jacksonObjectMapper()
    }

    @Test
    fun json() {
        val p = Person(32, "changyong", true)
        val json = objectMapper.writeValueAsString(p)

        val expected = """
            {"age":32,"name":"changyong","junior":true}
        """.trimIndent()

        assertThat(json).isEqualTo(expected)
    }
}

This result is {"age":32,"name":"changyong","junior":true}

Versions
Kotlin:
Jackson-module-kotlin: 2.10.1 or higher
Jackson-databind: 2.10.4

Additional context
Does changed spec on serialize isXXX properties? or bug?

Thank you.

@LichKing-lee
Copy link
Author

Attach Person class

data class Person(
    val age: Int,
    val name: String,
    val isJunior: Boolean
)

@LichKing-lee
Copy link
Author

I looked #80 and release note at https://github.com/FasterXML/jackson-module-kotlin/blob/master/release-notes/VERSION-2.x
Is there a way to keep it existing on 2.10.1 or higher?

@usulkies
Copy link

usulkies commented Jun 1, 2020

Hi @LichKing-lee .
We also experienced some severe bugs when we upgraded to Jackson 2.10.
But after all, this is the right behavior. The property name should be serialized as-is and the "is" should not be omitted. Also, this was not working on both serialization and deserialization. So services could not talk to each other because the receiving service didn't knew the property name without the "is".

There is a workaround if it's breaking things, and this is to add the @JsonProperty ("junior") annotation on the property and then it'll be serialized like before.
You can also configure a custom strategy to your mapper when the function name is starting with "is" and it's a boolean (Jackson sees Kotlin's properties as functions).

@dinomite dinomite changed the title Does changed spec on serialize isXXX properties? Serialization of isXXX fields changed in 2.10.1, adding is prefix which was previously absent Dec 19, 2020
@dinomite
Copy link
Member

@tokuhirom described it succinctly in #394:

Serialization result of the following code is incompatible between jackson-module-kotlin 2.10.0 and 2.10.1.

data class FooKt(var isUsingBar: Boolean)

Jackson version: 2.10.0
{"usingBar":true}
Jackson version: 2.10.1
{"isUsingBar":true}

They also create a repro https://github.com/tokuhirom/jackson-field-name-incompatiblity

@dinomite
Copy link
Member

dinomite commented Mar 6, 2021

We will track this in #337

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants