Skip to content

Commit efd53d2

Browse files
authored
WIP: test case for issue 505 (#506)
1 parent e34c5a3 commit efd53d2

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,10 +1,22 @@
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
57
import org.junit.runner.RunWith
68
import org.scalatestplus.junit.JUnitRunner
79

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+
820
object CreatorTest
921
{
1022
class CreatorTestBean(val a: String, var b: String)
@@ -52,7 +64,6 @@ object CreatorTest
5264
case class ConstructorWithOptionStruct(s: Option[Struct1] = None)
5365
}
5466

55-
5667
@RunWith(classOf[JUnitRunner])
5768
class CreatorTest extends DeserializationFixture {
5869
import CreatorTest._
@@ -154,4 +165,9 @@ class CreatorTest extends DeserializationFixture {
154165
deser2.s shouldEqual Some(new Struct1("name"){})
155166
f.writeValueAsString(ConstructorWithOptionStruct()) shouldEqual """{"s":null}"""
156167
}
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+
}
157173
}

0 commit comments

Comments
 (0)