@@ -2,17 +2,22 @@ package com.fasterxml.jackson.module.kotlin.test
2
2
3
3
import com.fasterxml.jackson.databind.ObjectMapper
4
4
import com.fasterxml.jackson.databind.SerializationFeature
5
- import com.fasterxml.jackson.module.kotlin.*
5
+ import com.fasterxml.jackson.module.kotlin.NullInputException
6
+ import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
7
+ import com.fasterxml.jackson.module.kotlin.readValue
6
8
import org.hamcrest.CoreMatchers.equalTo
7
9
import org.hamcrest.MatcherAssert.assertThat
10
+ import org.junit.Assert.assertNull
11
+ import org.junit.Assert.assertThrows
8
12
import org.junit.Test
9
13
10
14
class TestExtensionMethods {
11
15
val mapper: ObjectMapper = jacksonObjectMapper().configure(SerializationFeature .INDENT_OUTPUT , false )
12
16
13
- data class BasicPerson (val name : String , val age : Int )
17
+ @Test
18
+ fun testAllInferenceForms () {
19
+ data class BasicPerson (val name : String , val age : Int )
14
20
15
- @Test fun testAllInferenceForms () {
16
21
val json = """ {"name":"John Smith","age":30}"""
17
22
18
23
val inferRightSide = mapper.readValue<BasicPerson >(json)
@@ -26,11 +31,25 @@ class TestExtensionMethods {
26
31
assertThat(person, equalTo(expectedPerson))
27
32
}
28
33
29
- data class MyData (val a : String , val b : Int )
34
+ /* *
35
+ * https://stackoverflow.com/questions/33368328/how-to-use-jackson-to-deserialize-to-kotlin-collections
36
+ */
37
+ @Test
38
+ fun testStackOverflow33368328 () {
39
+ data class MyData (val a : String , val b : Int )
30
40
31
- @Test fun testStackOverflow33368328 () {
32
41
val jsonStr = """ [{"a": "value1", "b": 1}, {"a": "value2", "b": 2}]"""
33
42
val myList: List <MyData > = mapper.readValue(jsonStr)
34
43
assertThat(myList, equalTo(listOf (MyData (" value1" , 1 ), MyData (" value2" , 2 ))))
35
44
}
36
- }
45
+
46
+ enum class Options { ONE , TWO }
47
+
48
+ @Test
49
+ fun testNullEnumThrows () {
50
+ assertThrows(NullInputException ::class .java) {
51
+ val foo: Options = mapper.readValue(" null" )
52
+ assertNull(foo)
53
+ }
54
+ }
55
+ }
0 commit comments