@@ -3,7 +3,8 @@ package com.fasterxml.jackson.module.scala.deser
3
3
import com .fasterxml .jackson .databind .annotation .JsonDeserialize
4
4
import com .fasterxml .jackson .databind .exc .InvalidFormatException
5
5
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
7
8
import org .scalatest .BeforeAndAfterEach
8
9
9
10
object OptionWithNumberDeserializerTest {
@@ -25,7 +26,7 @@ class OptionWithNumberDeserializerTest extends DeserializerTest with BeforeAndAf
25
26
26
27
override def afterEach (): Unit = {
27
28
super .afterEach()
28
- ScalaAnnotationIntrospector .clearRegisteredReferencedTypes()
29
+ ScalaAnnotationIntrospectorModule .clearRegisteredReferencedTypes()
29
30
}
30
31
31
32
" JacksonModuleScala" should " deserialize AnnotatedOptionLong" in {
@@ -43,7 +44,7 @@ class OptionWithNumberDeserializerTest extends DeserializerTest with BeforeAndAf
43
44
}
44
45
45
46
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 ])
47
48
try {
48
49
val v1 = deserialize(""" {"valueLong":151}""" , classOf [OptionLong ])
49
50
v1 shouldBe OptionLong (Some (151L ))
@@ -52,12 +53,26 @@ class OptionWithNumberDeserializerTest extends DeserializerTest with BeforeAndAf
52
53
// or use one of the equivalent classes in OptionWithNumberDeserializerTest
53
54
useOptionLong(v1.valueLong) shouldBe 302L
54
55
} 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()
56
71
}
57
72
}
58
73
59
74
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 ])
61
76
try {
62
77
val v1 = deserialize(""" {"text":"myText","wrappedLong":{"valueLong":151}}""" , classOf [WrappedOptionLong ])
63
78
v1 shouldBe WrappedOptionLong (" myText" , OptionLong (Some (151L )))
@@ -66,7 +81,7 @@ class OptionWithNumberDeserializerTest extends DeserializerTest with BeforeAndAf
66
81
// or use one of the equivalent classes in OptionWithNumberDeserializerTest
67
82
useOptionLong(v1.wrappedLong.valueLong) shouldBe 302L
68
83
} finally {
69
- ScalaAnnotationIntrospector .clearRegisteredReferencedTypes()
84
+ ScalaAnnotationIntrospectorModule .clearRegisteredReferencedTypes()
70
85
}
71
86
}
72
87
0 commit comments