Skip to content

Make nulls = FAIL work even for primitives and missing #739

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

Merged
merged 1 commit into from
Dec 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ internal class KotlinValueInstantiator(
paramDef.isOptional -> return@forEachIndexed
// do not try to create any object if it is nullable and the value is missing
paramType.isMarkedNullable -> null
// Primitive types always try to get from a buffer, considering several settings
jsonProp.type.isPrimitive -> buffer.getParameter(jsonProp)
// to get suitable "missing" value provided by deserializer
else -> jsonProp.valueDeserializer?.getAbsentValue(ctxt)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.fasterxml.jackson.module.kotlin.test.github

import com.fasterxml.jackson.annotation.JsonSetter
import com.fasterxml.jackson.annotation.Nulls
import com.fasterxml.jackson.databind.exc.MismatchedInputException
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue
import org.junit.Assert.assertThrows
import org.junit.Test

class Github738 {
data class D(@JsonSetter(nulls = Nulls.FAIL) val v: Int)

@Test
fun test() {
val mapper = jacksonObjectMapper()
// nulls = FAIL is reflected if it is primitive and missing
assertThrows(MismatchedInputException::class.java) { mapper.readValue<D>("{}") }
}
}