Skip to content

Boolean property name starting with 'is' not serialized/deserialized properlyΒ #80

@tbvh

Description

@tbvh

Hi,
I'm experiencing issues with a boolean property which name starts with 'is'.
While the getter doesn't get prefixed by kotlin, it seems that jackson still strips away 'is' as though it was a prefix. The resulting json doesn't contain the 'is', and deserialization fails.

This test illustrates the problem:

class SerializationTest {
    @Test
    fun testIsBool() {
        val mapper = ObjectMapper()
        mapper.registerModule(KotlinModule())

        val example = IsBoolExample(true)
        val json = mapper.writeValueAsString(example) 
        // json contains: {"trueOrFalse":true}

        val deserialized = mapper.readValue(json, IsBoolExample::class.java)

        Assert.assertEquals(example.isTrueOrFalse, deserialized.isTrueOrFalse)
    }
}
class IsBoolExample(val isTrueOrFalse: Boolean)

This fails on mapper.readValue(..) with:

com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of com.bol.service.reptile.spring.IsBoolExample: no suitable constructor found, can not deserialize from Object value (missing default constructor or creator, or perhaps need to add/enable type information?)
at [Source: {"trueOrFalse":true}; line: 1, column: 2]

Metadata

Metadata

Assignees

No one assigned

    Labels

    is-prefixIssues relating to is-prefixed fields

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions