FasterXML / jackson-module-kotlin

Module that adds support for serialization/deserialization of Kotlin (http://kotlinlang.org) classes and data classes.
Apache License 2.0
1.12k stars 175 forks source link

Boolean property setter is skipped if name isX prefixed #798

Open IceBlizz6 opened 5 months ago

IceBlizz6 commented 5 months ago

Search before asking

Describe the bug

Jackson will not call property setter for boolean properties if the name is prefixed with isX. Value is still assigned, which makes me suspect that it is assigning value to the backing field directly instead.

To Reproduce

import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue
import org.junit.Assert
import org.junit.Test

class ReadTest {
    class Dummy {
        var isAlive: Boolean? = null
            set(value) {
                field = value
                setterUsed = true
            }

        var setterUsed = false
    }

    @Test
    fun readPrefixedValueTest() {
        val objectMapper = jacksonObjectMapper()
        val dummy = objectMapper.readValue<Dummy>("{ \"isAlive\": true }")
        Assert.assertTrue(dummy.setterUsed)
    }
}

Expected behavior

When running the reproduction case then the test should succeed. The setter of isAlive property should be called.

Versions

Kotlin: 1.9.23 Jackson-module-kotlin: 2.17.1

Additional context

No response

k163377 commented 3 months ago

Confirmed. The KotlinModule does not currently assume deserialization using setter, which seems to be a missing feature. https://github.com/FasterXML/jackson-module-kotlin/blob/c0457486720ffa4318e5d8acd63e758e160cf24b/src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinNamesAnnotationIntrospector.kt#L66-L71

Since implementation is undecided, please use a workaround such as JsonProperty.

IceBlizz6 commented 3 months ago

Thank you for your response.

Is there hope for a real solution on this in the future? (other than the workaround)

AnneMayor commented 2 months ago

I am also curious if this feature could be released for some day.

k163377 commented 3 weeks ago

At least I don't have time to work on it.