Skip to content

Commit b58ead1

Browse files
committed
Update CreatorTest.scala (#507)
(cherry picked from commit cd885d2)
1 parent d0bd40e commit b58ead1

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
package com.fasterxml.jackson.module.scala.deser
22

33
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
7+
8+
class PositiveLong private (val value: Long) {
9+
override def toString() = s"PositiveLong($value)"
10+
}
11+
object PositiveLong {
12+
@JsonCreator
13+
def apply(long: Long): PositiveLong = new PositiveLong(long)
14+
@JsonCreator
15+
def apply(str: String): PositiveLong = new PositiveLong(str.toLong)
16+
}
517

618
object CreatorTest
719
{
@@ -50,7 +62,6 @@ object CreatorTest
5062
case class ConstructorWithOptionStruct(s: Option[Struct1] = None)
5163
}
5264

53-
5465
class CreatorTest extends DeserializationFixture {
5566
import CreatorTest._
5667

@@ -147,4 +158,9 @@ class CreatorTest extends DeserializationFixture {
147158
deser2.s shouldEqual Some(Struct1("name"))
148159
f.writeValueAsString(ConstructorWithOptionStruct()) shouldEqual """{"s":null}"""
149160
}
161+
162+
it should "support multiple creator annotations" in { f =>
163+
val node: JsonNode = f.valueToTree[IntNode](10)
164+
f.convertValue(node, new TypeReference[PositiveLong] {}).value shouldEqual node.asLong()
165+
}
150166
}

0 commit comments

Comments
 (0)