File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
src/test/kotlin/com/fasterxml/jackson/module/kotlin/test Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments