@@ -2,7 +2,9 @@ package com.fasterxml.jackson.module.scala.deser
2
2
3
3
import com .fasterxml .jackson .core .`type` .TypeReference
4
4
import com .fasterxml .jackson .module .scala .DefaultScalaModule
5
+ import com .fasterxml .jackson .module .scala .deser .IntMapDeserializerTest .Event
5
6
7
+ import java .util .UUID
6
8
import scala .collection .{immutable , mutable }
7
9
8
10
class LongMapDeserializerTest extends DeserializerTest {
@@ -45,6 +47,54 @@ class LongMapDeserializerTest extends DeserializerTest {
45
47
read(402 ) shouldBe true
46
48
}
47
49
50
+ it should " deserialize immutable LongMap (Object values)" in {
51
+ val event = Event (UUID .randomUUID(), " event1" )
52
+ val map = mutable.LongMap (0L -> false , 1L -> " true" , 2L -> event)
53
+ val mapper = newMapper
54
+ val json = mapper.writeValueAsString(map)
55
+ val read = mapper.readValue(json, classOf [immutable.LongMap [Any ]])
56
+ read(0 ) shouldBe false
57
+ read(1 ) shouldEqual " true"
58
+ read(2 ) shouldEqual Map (" id" -> event.id.toString, " description" -> event.description)
59
+ }
60
+
61
+ it should " deserialize immutable LongMap (Object values, duplicate keys - default mode)" in {
62
+ val mapper = newMapper
63
+ val json = """ {"1": 123, "2": 123, "2": 123.456}"""
64
+ val read = mapper.readValue(json, classOf [immutable.LongMap [Any ]])
65
+ read(1 ) shouldEqual 123
66
+ read(2 ) shouldEqual 123.456
67
+ }
68
+
69
+ it should " deserialize immutable LongMap (Object values, duplicate keys - optional mode)" in {
70
+ val mapper = newMapper
71
+ val json = """ {"1": 123, "2": 123, "2": 123.456}"""
72
+ val parser = new WithDupsParser (mapper.createParser(json))
73
+ val read = try {
74
+ mapper.readValue(parser, classOf [immutable.LongMap [Any ]])
75
+ } finally {
76
+ parser.close()
77
+ }
78
+ read(1 ) shouldEqual 123
79
+ val expected = new java.util.ArrayList [Object ]()
80
+ expected.add(java.lang.Integer .valueOf(123 ))
81
+ expected.add(java.lang.Double .valueOf(123.456 ))
82
+ read(2 ) shouldEqual expected
83
+ }
84
+
85
+ it should " deserialize immutable LongMap (Double values, duplicate key mode is ignored)" in {
86
+ val mapper = newMapper
87
+ val json = """ {"1": "123", "2": "123", "2": "123.456"}"""
88
+ val parser = new WithDupsParser (mapper.createParser(json))
89
+ val read = try {
90
+ mapper.readValue(parser, new TypeReference [immutable.LongMap [String ]] {})
91
+ } finally {
92
+ parser.close()
93
+ }
94
+ read(1 ) shouldEqual " 123"
95
+ read(2 ) shouldEqual " 123.456"
96
+ }
97
+
48
98
it should " deserialize mutable LongMap" in {
49
99
val map = mutable.LongMap (1L -> " one" , 2L -> " two" )
50
100
@@ -80,4 +130,52 @@ class LongMapDeserializerTest extends DeserializerTest {
80
130
read(0 ) shouldBe false
81
131
read(402 ) shouldBe true
82
132
}
133
+
134
+ it should " deserialize mutable LongMap (Object values)" in {
135
+ val event = Event (UUID .randomUUID(), " event1" )
136
+ val map = mutable.LongMap (0L -> false , 1L -> " true" , 2L -> event)
137
+ val mapper = newMapper
138
+ val json = mapper.writeValueAsString(map)
139
+ val read = mapper.readValue(json, classOf [mutable.LongMap [Any ]])
140
+ read(0 ) shouldBe false
141
+ read(1 ) shouldEqual " true"
142
+ read(2 ) shouldEqual Map (" id" -> event.id.toString, " description" -> event.description)
143
+ }
144
+
145
+ it should " deserialize mutable LongMap (Object values, duplicate keys - default mode)" in {
146
+ val mapper = newMapper
147
+ val json = """ {"1": 123, "2": 123, "2": 123.456}"""
148
+ val read = mapper.readValue(json, classOf [mutable.LongMap [Any ]])
149
+ read(1 ) shouldEqual 123
150
+ read(2 ) shouldEqual 123.456
151
+ }
152
+
153
+ it should " deserialize mutable LongMap (Object values, duplicate keys - optional mode)" in {
154
+ val mapper = newMapper
155
+ val json = """ {"1": 123, "2": 123, "2": 123.456}"""
156
+ val parser = new WithDupsParser (mapper.createParser(json))
157
+ val read = try {
158
+ mapper.readValue(parser, classOf [mutable.LongMap [Any ]])
159
+ } finally {
160
+ parser.close()
161
+ }
162
+ read(1 ) shouldEqual 123
163
+ val expected = new java.util.ArrayList [Object ]()
164
+ expected.add(java.lang.Integer .valueOf(123 ))
165
+ expected.add(java.lang.Double .valueOf(123.456 ))
166
+ read(2 ) shouldEqual expected
167
+ }
168
+
169
+ it should " deserialize mutable LongMap (Double values, duplicate key mode is ignored)" in {
170
+ val mapper = newMapper
171
+ val json = """ {"1": "123", "2": "123", "2": "123.456"}"""
172
+ val parser = new WithDupsParser (mapper.createParser(json))
173
+ val read = try {
174
+ mapper.readValue(parser, new TypeReference [mutable.LongMap [String ]] {})
175
+ } finally {
176
+ parser.close()
177
+ }
178
+ read(1 ) shouldEqual " 123"
179
+ read(2 ) shouldEqual " 123.456"
180
+ }
83
181
}
0 commit comments