FasterXML/jackson-module-kotlin

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

Closed this issue · 1 comments

dobe commented

Search before asking

  • I searched in the issues and found nothing similar.
  • I searched in the issues of databind and other modules used and found nothing similar.
  • I have confirmed that the problem only occurs when using Kotlin.

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

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.
FasterXML/jackson-databind#3079 (comment)