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

Complex Object beginning with 'is' is not serialised #453

Closed
karsunke opened this issue May 27, 2021 · 1 comment
Closed

Complex Object beginning with 'is' is not serialised #453

karsunke opened this issue May 27, 2021 · 1 comment
Labels
is-prefix Issues relating to is-prefixed fields

Comments

@karsunke
Copy link

Naming an object attribute beginning with 'is' leads to not being serialised at all. This issue was fixed for booleans: #80

But still exists if we use an object:

import com.fasterxml.jackson.databind.ObjectMapper

data class Model(
    val isActive: Boolean,
    val isAvailable: EmbeddedModel
)

data class EmbeddedModel(
    val value: Boolean,
    val metaData: String
)

fun main() {

    val model = Model(
        isActive = true,
        isAvailable = EmbeddedModel(
            value = true,
            metaData = "someString"
        )
    )

    val objectMapper = ObjectMapper()

    println(objectMapper.writeValueAsString(model))
}

prints just {"active":true} It ignores isAvailable completely. This happens with 2.11.4 and 2.12.3. I also created a sample project to demonstrate this issue:

https://github.com/karsunke/jackson-kotlin-boolean

@dinomite
Copy link
Member

Thanks for the report.

is-prefixed fields are only serialized if they are boolean, in accordance with the Java Beans spec §8.3.2. See further discussion in #337

You can override this behavior with a get use-site target. Example in this test:
https://github.com/FasterXML/jackson-module-kotlin/blob/2.12/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/failing/GitHub337.kt#L55

@dinomite dinomite added the is-prefix Issues relating to is-prefixed fields label Aug 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
is-prefix Issues relating to is-prefixed fields
Projects
None yet
Development

No branches or pull requests

2 participants