Skip to content

Commit 86e1700

Browse files
committed
Add FailNullForPrimitive test
1 parent c9d7092 commit 86e1700

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.fasterxml.jackson.module.kotlin.test
2+
3+
import com.fasterxml.jackson.databind.DeserializationFeature
4+
import com.fasterxml.jackson.databind.exc.MismatchedInputException
5+
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
6+
import com.fasterxml.jackson.module.kotlin.readValue
7+
import junit.framework.TestCase.assertEquals
8+
import org.junit.Assert.assertThrows
9+
import kotlin.test.Test
10+
11+
class FailNullForPrimitiveTest {
12+
data class Dto(
13+
val foo: Int,
14+
val bar: Int?
15+
)
16+
17+
@Test
18+
fun test() {
19+
val mapper = jacksonObjectMapper()
20+
.enable(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES)
21+
22+
assertThrows(MismatchedInputException::class.java) {
23+
mapper.readValue<Dto>("{}")
24+
}
25+
26+
assertThrows(MismatchedInputException::class.java) {
27+
mapper.readValue<Dto>("""{"foo":null}""")
28+
}
29+
30+
assertEquals(Dto(0, null), mapper.readValue<Dto>("""{"foo":0}"""))
31+
}
32+
}

0 commit comments

Comments
 (0)