File tree 3 files changed +52
-0
lines changed
java/com/fasterxml/jackson/module/scala/deser
scala/com/fasterxml/jackson/module/scala/deser
3 files changed +52
-0
lines changed Original file line number Diff line number Diff line change
1
+ package com .fasterxml .jackson .module .scala .deser ;
2
+
3
+ public class UserOfValueHolder {
4
+
5
+ private ValueHolder valueHolder ;
6
+
7
+ public UserOfValueHolder () {
8
+ }
9
+
10
+ public ValueHolder getValueHolder () {
11
+ return valueHolder ;
12
+ }
13
+
14
+ public void setValueHolder (ValueHolder valueHolder ) {
15
+ this .valueHolder = valueHolder ;
16
+ }
17
+ }
Original file line number Diff line number Diff line change
1
+ package com .fasterxml .jackson .module .scala .deser ;
2
+
3
+ import com .fasterxml .jackson .annotation .JsonCreator ;
4
+
5
+ public class ValueHolder {
6
+
7
+ public final long internalValue ;
8
+
9
+ private ValueHolder (long internalValue ) {
10
+ this .internalValue = internalValue ;
11
+ }
12
+
13
+ @ JsonCreator
14
+ public static ValueHolder parse (String value ) {
15
+ return new ValueHolder (Long .parseLong (value ));
16
+ }
17
+
18
+ }
Original file line number Diff line number Diff line change 1
1
package com .fasterxml .jackson .module .scala .deser
2
2
3
+ import java .util .concurrent .TimeUnit
4
+
3
5
import com .fasterxml .jackson .annotation .JsonCreator
6
+ import com .fasterxml .jackson .databind .ObjectMapper
4
7
import org .junit .runner .RunWith
5
8
import org .scalatest .junit .JUnitRunner
6
9
import org .scalatest .matchers .ShouldMatchers
@@ -43,4 +46,18 @@ class CreatorTest extends DeserializationFixture {
43
46
val bean = f.readValue[CreatorModeWrapper ](""" {"a":"foo"}""" )
44
47
bean.a.s shouldEqual " foo"
45
48
}
49
+
50
+ it should " work with static method creator" in { f =>
51
+ val json = """ {"valueHolder": "2"}"""
52
+
53
+ val regularObjectMapper = new ObjectMapper ()
54
+
55
+ // Using regular objectMapper
56
+ val bean1 = regularObjectMapper.readValue(json, classOf [UserOfValueHolder ])
57
+ bean1.getValueHolder.internalValue shouldEqual 2L
58
+
59
+ // Using objectMapper with DefaultScalaModule
60
+ val bean2 = f.readValue[UserOfValueHolder ](json)
61
+ bean2.getValueHolder.internalValue shouldEqual 2L
62
+ }
46
63
}
You can’t perform that action at this time.
0 commit comments