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

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

Closed
3 tasks done
dobe opened this issue Feb 8, 2024 · 1 comment
Closed
3 tasks done
Labels

Comments

@dobe
Copy link

dobe commented Feb 8, 2024

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

@k163377
Copy link
Contributor

k163377 commented Apr 13, 2024

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)

@k163377 k163377 closed this as completed Apr 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants