Skip to content

Commit d01c5b2

Browse files
committed
Merge pull request #230 from mbknor/test-that-shows-problem-with-static-creator-method
Adds test that asserts that Static @JsonCreator method does work - refs #229
2 parents afade1b + 9843de7 commit d01c5b2

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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 numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
}

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

100644100755
+17
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package com.fasterxml.jackson.module.scala.deser
22

3+
import java.util.concurrent.TimeUnit
4+
35
import com.fasterxml.jackson.annotation.JsonCreator
6+
import com.fasterxml.jackson.databind.ObjectMapper
47
import org.junit.runner.RunWith
58
import org.scalatest.junit.JUnitRunner
69
import org.scalatest.matchers.ShouldMatchers
@@ -43,4 +46,18 @@ class CreatorTest extends DeserializationFixture {
4346
val bean = f.readValue[CreatorModeWrapper]("""{"a":"foo"}""")
4447
bean.a.s shouldEqual "foo"
4548
}
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+
}
4663
}

0 commit comments

Comments
 (0)