Skip to content

Commit a73d2a2

Browse files
committed
Update OptionWithNumberDeserializerTest.scala
1 parent 165021b commit a73d2a2

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

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

+21-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ package com.fasterxml.jackson.module.scala.deser
33
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
44
import com.fasterxml.jackson.databind.exc.InvalidFormatException
55
import com.fasterxml.jackson.module.scala.DefaultScalaModule
6-
import com.fasterxml.jackson.module.scala.introspect.ScalaAnnotationIntrospector
6+
import com.fasterxml.jackson.module.scala.deser.PrimitiveContainerTest.OptionLongWithDefault
7+
import com.fasterxml.jackson.module.scala.introspect.ScalaAnnotationIntrospectorModule
78
import org.scalatest.BeforeAndAfterEach
89

910
object OptionWithNumberDeserializerTest {
@@ -25,7 +26,7 @@ class OptionWithNumberDeserializerTest extends DeserializerTest with BeforeAndAf
2526

2627
override def afterEach(): Unit = {
2728
super.afterEach()
28-
ScalaAnnotationIntrospector.clearRegisteredReferencedTypes()
29+
ScalaAnnotationIntrospectorModule.clearRegisteredReferencedTypes()
2930
}
3031

3132
"JacksonModuleScala" should "deserialize AnnotatedOptionLong" in {
@@ -43,7 +44,7 @@ class OptionWithNumberDeserializerTest extends DeserializerTest with BeforeAndAf
4344
}
4445

4546
it should "deserialize OptionLong when registerReferencedValueType is used" in {
46-
ScalaAnnotationIntrospector.registerReferencedValueType(classOf[OptionLong], "valueLong", classOf[Long])
47+
ScalaAnnotationIntrospectorModule.registerReferencedValueType(classOf[OptionLong], "valueLong", classOf[Long])
4748
try {
4849
val v1 = deserialize("""{"valueLong":151}""", classOf[OptionLong])
4950
v1 shouldBe OptionLong(Some(151L))
@@ -52,12 +53,26 @@ class OptionWithNumberDeserializerTest extends DeserializerTest with BeforeAndAf
5253
//or use one of the equivalent classes in OptionWithNumberDeserializerTest
5354
useOptionLong(v1.valueLong) shouldBe 302L
5455
} finally {
55-
ScalaAnnotationIntrospector.clearRegisteredReferencedTypes()
56+
ScalaAnnotationIntrospectorModule.clearRegisteredReferencedTypes()
57+
}
58+
}
59+
60+
it should "deserialize OptionLongWithDefault when registerReferencedValueType is used" in {
61+
ScalaAnnotationIntrospectorModule.registerReferencedValueType(classOf[OptionLongWithDefault], "valueLong", classOf[Long])
62+
try {
63+
val v1 = deserialize("""{"valueLong":151}""", classOf[OptionLong])
64+
v1 shouldBe OptionLong(Some(151L))
65+
v1.valueLong.get shouldBe 151L
66+
//this next call will fail with a Scala unboxing exception unless you call ScalaAnnotationIntrospectorModule.registerReferencedValueType
67+
//or use one of the equivalent classes in OptionWithNumberDeserializerTest
68+
useOptionLong(v1.valueLong) shouldBe 302L
69+
} finally {
70+
ScalaAnnotationIntrospectorModule.clearRegisteredReferencedTypes()
5671
}
5772
}
5873

5974
it should "deserialize WrappedOptionLong when registerReferencedValueType is used" in {
60-
ScalaAnnotationIntrospector.registerReferencedValueType(classOf[OptionLong], "valueLong", classOf[Long])
75+
ScalaAnnotationIntrospectorModule.registerReferencedValueType(classOf[OptionLong], "valueLong", classOf[Long])
6176
try {
6277
val v1 = deserialize("""{"text":"myText","wrappedLong":{"valueLong":151}}""", classOf[WrappedOptionLong])
6378
v1 shouldBe WrappedOptionLong("myText", OptionLong(Some(151L)))
@@ -66,7 +81,7 @@ class OptionWithNumberDeserializerTest extends DeserializerTest with BeforeAndAf
6681
//or use one of the equivalent classes in OptionWithNumberDeserializerTest
6782
useOptionLong(v1.wrappedLong.valueLong) shouldBe 302L
6883
} finally {
69-
ScalaAnnotationIntrospector.clearRegisteredReferencedTypes()
84+
ScalaAnnotationIntrospectorModule.clearRegisteredReferencedTypes()
7085
}
7186
}
7287

0 commit comments

Comments
 (0)