Skip to content

2.12 creator test #507

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 1 commit 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,7 +1,19 @@
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

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
{
Expand Down Expand Up @@ -50,7 +62,6 @@ object CreatorTest
case class ConstructorWithOptionStruct(s: Option[Struct1] = None)
}


class CreatorTest extends DeserializationFixture {
import CreatorTest._

Expand Down Expand Up @@ -147,4 +158,9 @@ class CreatorTest extends DeserializationFixture {
deser2.s shouldEqual Some(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()
}
}