Skip to content

Commit a8a7990

Browse files
committed
Merge branch '2.12' into dotty
2 parents ec0d95f + f8b7981 commit a8a7990

File tree

2 files changed

+39
-53
lines changed

2 files changed

+39
-53
lines changed

src/test/scala/com/fasterxml/jackson/module/external/CustomScalaModuleTest.scala

Lines changed: 0 additions & 32 deletions
This file was deleted.

src/test/scala/com/fasterxml/jackson/module/scala/deser/MergeTest.scala

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package com.fasterxml.jackson.module.scala.deser
22

33
import com.fasterxml.jackson.annotation.JsonMerge
44
import com.fasterxml.jackson.core.`type`.TypeReference
5-
import com.fasterxml.jackson.databind.ObjectMapper
6-
import com.fasterxml.jackson.module.scala.{DefaultScalaModule, ScalaObjectMapper}
5+
import com.fasterxml.jackson.databind.{ObjectMapper, ObjectReader}
6+
import com.fasterxml.jackson.module.scala.DefaultScalaModule
77

88
import scala.collection.{Map, mutable}
99

@@ -17,13 +17,13 @@ class MergeTest extends DeserializerTest {
1717

1818
val module: DefaultScalaModule.type = DefaultScalaModule
1919

20-
def newScalaMapper: ObjectMapper with ScalaObjectMapper = {
21-
val mapper = new ObjectMapper with ScalaObjectMapper
20+
def newScalaMapper: ObjectMapper = {
21+
val mapper = new ObjectMapper
2222
mapper.registerModule(module)
2323
mapper
2424
}
2525

26-
def newMergeableScalaMapper: ObjectMapper with ScalaObjectMapper = {
26+
def newMergeableScalaMapper: ObjectMapper = {
2727
val mapper = newScalaMapper
2828
mapper.setDefaultMergeable(true)
2929
mapper
@@ -32,57 +32,65 @@ class MergeTest extends DeserializerTest {
3232
behavior of "The DefaultScalaModule when reading for updating"
3333

3434
it should "merge both lists" in {
35-
val initial = deserialize(classJson(firstListJson), classOf[ClassWithLists])
36-
val result = newMergeableScalaMapper.updateValue(initial, classJson(secondListJson))
35+
val typeReference = new TypeReference[ClassWithLists] {}
36+
val initial = deserialize(classJson(firstListJson), typeReference)
37+
val result = updateValue(newMergeableScalaMapper, initial, typeReference, classJson(secondListJson))
3738

3839
result shouldBe ClassWithLists(mergedList, mergedList)
3940
}
4041

4142
it should "merge only the annotated list" in {
42-
val initial = deserialize(classJson(firstListJson), classOf[ClassWithLists])
43-
val result = newScalaMapper.updateValue(initial, classJson(secondListJson))
43+
val typeReference = new TypeReference[ClassWithLists] {}
44+
val initial = deserialize(classJson(firstListJson), typeReference)
45+
val result = updateValue(newScalaMapper, initial, typeReference, classJson(secondListJson))
4446

4547
result shouldBe ClassWithLists(secondList, mergedList)
4648
}
4749

4850
it should "merge both string maps" in {
49-
val initial = deserialize(classJson(firstStringMapJson), classOf[ClassWithMaps[String]])
50-
val result = newMergeableScalaMapper.updateValue(initial, classJson(secondStringMapJson))
51+
val typeReference = new TypeReference[ClassWithMaps[String]] {}
52+
val initial = deserialize(classJson(firstStringMapJson), typeReference)
53+
val result = updateValue(newMergeableScalaMapper, initial, typeReference, classJson(secondStringMapJson))
5154

5255
result shouldBe ClassWithMaps(mergedStringMap, mergedStringMap)
5356
}
5457

5558
it should "merge only the annotated string map" in {
56-
val initial = deserialize(classJson(firstStringMapJson), classOf[ClassWithMaps[String]])
57-
val result = newScalaMapper.updateValue(initial, classJson(secondStringMapJson))
59+
val typeReference = new TypeReference[ClassWithMaps[String]] {}
60+
val initial = deserialize(classJson(firstStringMapJson), typeReference)
61+
val result = updateValue(newScalaMapper, initial, typeReference, classJson(secondStringMapJson))
5862

5963
result shouldBe ClassWithMaps(secondStringMap, mergedStringMap)
6064
}
6165

6266
it should "merge both pair maps" in {
63-
val initial = deserialize(classJson(firstPairMapJson), new TypeReference[ClassWithMaps[Pair]]{})
64-
val result = newMergeableScalaMapper.updateValue(initial, classJson(secondPairMapJson))
67+
val typeReference = new TypeReference[ClassWithMaps[Pair]] {}
68+
val initial = deserialize(classJson(firstPairMapJson), typeReference)
69+
val result = updateValue(newMergeableScalaMapper, initial, typeReference, classJson(secondPairMapJson))
6570

6671
result shouldBe ClassWithMaps(mergedPairMap, mergedPairMap)
6772
}
6873

6974
it should "merge only the annotated pair map" in {
70-
val initial = deserialize(classJson(firstPairMapJson), new TypeReference[ClassWithMaps[Pair]]{})
71-
val result = newScalaMapper.updateValue(initial, classJson(secondPairMapJson))
75+
val typeReference = new TypeReference[ClassWithMaps[Pair]]{}
76+
val initial = deserialize(classJson(firstPairMapJson), typeReference)
77+
val result = updateValue(newScalaMapper, initial, typeReference, classJson(secondPairMapJson))
7278

7379
result shouldBe ClassWithMaps(secondPairMap, mergedPairMap)
7480
}
7581

7682
it should "merge both mutable maps" in {
77-
val initial = deserialize(classJson(firstStringMapJson), classOf[ClassWithMutableMaps[String]])
78-
val result = newMergeableScalaMapper.updateValue(initial, classJson(secondStringMapJson))
83+
val typeReference = new TypeReference[ClassWithMutableMaps[String]]{}
84+
val initial = deserialize(classJson(firstStringMapJson), typeReference)
85+
val result = updateValue(newMergeableScalaMapper, initial, typeReference, classJson(secondStringMapJson))
7986

8087
result shouldBe ClassWithMutableMaps(mutable.Map() ++ mergedStringMap, mutable.Map() ++ mergedStringMap)
8188
}
8289

8390
it should "merge only the annotated mutable map" in {
84-
val initial = deserialize(classJson(firstStringMapJson), classOf[ClassWithMutableMaps[String]])
85-
val result = newScalaMapper.updateValue(initial, classJson(secondStringMapJson))
91+
val typeReference = new TypeReference[ClassWithMutableMaps[String]]{}
92+
val initial = deserialize(classJson(firstStringMapJson), typeReference)
93+
val result = updateValue(newScalaMapper, initial, typeReference, classJson(secondStringMapJson))
8694

8795
result shouldBe ClassWithMutableMaps(mutable.Map() ++ secondStringMap, mutable.Map() ++ mergedStringMap)
8896
}
@@ -103,4 +111,14 @@ class MergeTest extends DeserializerTest {
103111
val secondPairMapJson = """{"two":{"first":"22"},"three":{"second":"33"}}"""
104112
val secondPairMap = Map("two" -> Pair("22", null), "three" -> Pair(null, "33"))
105113
val mergedPairMap = Map("one" -> Pair("1", null), "two" -> Pair("22", "2"), "three" -> Pair("3", "33"))
114+
115+
private def updateValue[T](mapper: ObjectMapper, valueToUpdate: T,
116+
typeReference: TypeReference[T], src: String): T = {
117+
objectReaderFor(mapper, valueToUpdate, typeReference).readValue(src)
118+
}
119+
120+
private def objectReaderFor[T](mapper: ObjectMapper, valueToUpdate: T,
121+
typeReference: TypeReference[T]): ObjectReader = {
122+
mapper.readerForUpdating(valueToUpdate).forType(typeReference)
123+
}
106124
}

0 commit comments

Comments
 (0)