|
1 | 1 | package com.fasterxml.jackson.module.scala.deser
|
2 | 2 |
|
3 | 3 | import com.fasterxml.jackson.annotation.JsonCreator
|
4 |
| -import com.fasterxml.jackson.databind.ObjectMapper |
| 4 | +import com.fasterxml.jackson.core.`type`.TypeReference |
| 5 | +import com.fasterxml.jackson.databind.{JsonNode, ObjectMapper} |
| 6 | +import com.fasterxml.jackson.databind.node.IntNode |
5 | 7 | import org.junit.runner.RunWith
|
6 | 8 | import org.scalatestplus.junit.JUnitRunner
|
7 | 9 |
|
| 10 | +class PositiveLong private (val value: Long) { |
| 11 | + override def toString() = s"PositiveLong($value)" |
| 12 | +} |
| 13 | +object PositiveLong { |
| 14 | + @JsonCreator |
| 15 | + def apply(long: Long): PositiveLong = new PositiveLong(long) |
| 16 | + @JsonCreator |
| 17 | + def apply(str: String): PositiveLong = new PositiveLong(str.toLong) |
| 18 | +} |
| 19 | + |
8 | 20 | object CreatorTest
|
9 | 21 | {
|
10 | 22 | class CreatorTestBean(val a: String, var b: String)
|
@@ -52,7 +64,6 @@ object CreatorTest
|
52 | 64 | case class ConstructorWithOptionStruct(s: Option[Struct1] = None)
|
53 | 65 | }
|
54 | 66 |
|
55 |
| - |
56 | 67 | @RunWith(classOf[JUnitRunner])
|
57 | 68 | class CreatorTest extends DeserializationFixture {
|
58 | 69 | import CreatorTest._
|
@@ -154,4 +165,9 @@ class CreatorTest extends DeserializationFixture {
|
154 | 165 | deser2.s shouldEqual Some(new Struct1("name"){})
|
155 | 166 | f.writeValueAsString(ConstructorWithOptionStruct()) shouldEqual """{"s":null}"""
|
156 | 167 | }
|
| 168 | + |
| 169 | + it should "support multiple creator annotations" in { f => |
| 170 | + val node: JsonNode = f.valueToTree[IntNode](10) |
| 171 | + f.convertValue(node, new TypeReference[PositiveLong] {}).value shouldEqual node.asLong() |
| 172 | + } |
157 | 173 | }
|
0 commit comments