Skip to content

test case for issue 505 #506

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 25, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
package com.fasterxml.jackson.module.scala.deser

import com.fasterxml.jackson.annotation.JsonCreator
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.core.`type`.TypeReference
import com.fasterxml.jackson.databind.{JsonNode, ObjectMapper}
import com.fasterxml.jackson.databind.node.IntNode
import org.junit.runner.RunWith
import org.scalatestplus.junit.JUnitRunner

class PositiveLong private (val value: Long) {
override def toString() = s"PositiveLong($value)"
}
object PositiveLong {
@JsonCreator
def apply(long: Long): PositiveLong = new PositiveLong(long)
@JsonCreator
def apply(str: String): PositiveLong = new PositiveLong(str.toLong)
}

object CreatorTest
{
class CreatorTestBean(val a: String, var b: String)
Expand Down Expand Up @@ -52,7 +64,6 @@ object CreatorTest
case class ConstructorWithOptionStruct(s: Option[Struct1] = None)
}


@RunWith(classOf[JUnitRunner])
class CreatorTest extends DeserializationFixture {
import CreatorTest._
Expand Down Expand Up @@ -154,4 +165,9 @@ class CreatorTest extends DeserializationFixture {
deser2.s shouldEqual Some(new Struct1("name"){})
f.writeValueAsString(ConstructorWithOptionStruct()) shouldEqual """{"s":null}"""
}

it should "support multiple creator annotations" in { f =>
val node: JsonNode = f.valueToTree[IntNode](10)
f.convertValue(node, new TypeReference[PositiveLong] {}).value shouldEqual node.asLong()
}
}