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.11k stars 175 forks source link

mapper.updateValue allows to set fields to null which are not nullable #766

Closed dobe closed 3 months ago

dobe commented 5 months ago

Search before asking

Describe the bug

here is a test that succeeds, which should not be possible since O.a is not nullable


import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import io.kotest.core.spec.style.StringSpec
import io.kotest.matchers.shouldBe

class O(val a: String)

class JsonTest : StringSpec({

    val mapper = jacksonObjectMapper()

    "test nulls are getting deserialized on non nullable type" {

        val updates = mapper.readTree("""{"a":null}""")
        val o = O("orig")
        val newO = mapper.updateValue(o, updates)
        newO.a shouldBe null

    }

})

To Reproduce

// Your code here

Expected behavior

the updateValue call should raise an error

Versions

Kotlin: 1.9.22 Jackson-module-kotlin: 2.15.3 Jackson-databind: 2.15.3

Additional context

No response

k163377 commented 3 months ago

This is the behavior introduced by databind and is difficult (or should not be) fixed by kotlin-module. I have left a comment on a similar problem in databind, so this issue is closed. https://github.com/FasterXML/jackson-databind/issues/3079#issuecomment-2053439572