Skip to content

Commit b7cc1a9

Browse files
committed
Make nulls = FAIL work even for primitives and missing
Fixed bug by FasterXML#738
1 parent cf890c6 commit b7cc1a9

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinValueInstantiator.kt

+2
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ internal class KotlinValueInstantiator(
7878
paramDef.isOptional -> return@forEachIndexed
7979
// do not try to create any object if it is nullable and the value is missing
8080
paramType.isMarkedNullable -> null
81+
// Primitive types always try to get from a buffer, considering several settings
82+
jsonProp.type.isPrimitive -> buffer.getParameter(jsonProp)
8183
// to get suitable "missing" value provided by deserializer
8284
else -> jsonProp.valueDeserializer?.getAbsentValue(ctxt)
8385
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.fasterxml.jackson.module.kotlin.test.github
2+
3+
import com.fasterxml.jackson.annotation.JsonSetter
4+
import com.fasterxml.jackson.annotation.Nulls
5+
import com.fasterxml.jackson.databind.exc.MismatchedInputException
6+
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
7+
import com.fasterxml.jackson.module.kotlin.readValue
8+
import org.junit.Assert.assertThrows
9+
import org.junit.Test
10+
11+
class Github738 {
12+
data class D(@JsonSetter(nulls = Nulls.FAIL) val v: Int)
13+
14+
@Test
15+
fun test() {
16+
val mapper = jacksonObjectMapper()
17+
// nulls = FAIL is reflected if it is primitive and missing
18+
assertThrows(MismatchedInputException::class.java) { mapper.readValue<D>("{}") }
19+
}
20+
}

0 commit comments

Comments
 (0)