Skip to content

Commit

Permalink
Merge pull request #739 from k163377/fix-nulls-fail
Browse files Browse the repository at this point in the history
Make nulls = FAIL work even for primitives and missing
  • Loading branch information
k163377 committed Dec 10, 2023
2 parents cf890c6 + b7cc1a9 commit b917694
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
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>("{}") }
}
}

0 comments on commit b917694

Please sign in to comment.