Skip to content

Commit

Permalink
2.12 creator test (#510)
Browse files Browse the repository at this point in the history
  • Loading branch information
pjfanning committed Feb 25, 2021
1 parent cd885d2 commit 3fa3ad5
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 44 deletions.
10 changes: 2 additions & 8 deletions build.sbt
Expand Up @@ -39,20 +39,14 @@ libraryDependencies ++= Seq(
"com.fasterxml.jackson.core" % "jackson-core" % jacksonVersion,
"com.fasterxml.jackson.core" % "jackson-annotations" % jacksonVersion,
"com.fasterxml.jackson.core" % "jackson-databind" % jacksonVersion,
) ++ {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, scalaMajor)) if scalaMajor <= 11 =>
Seq("com.thoughtworks.paranamer" % "paranamer" % "2.8")
case _ => Seq.empty
}
} ++ Seq(
"com.thoughtworks.paranamer" % "paranamer" % "2.8",
// test dependencies
"com.fasterxml.jackson.datatype" % "jackson-datatype-joda" % jacksonVersion % Test,
"com.fasterxml.jackson.datatype" % "jackson-datatype-guava" % jacksonVersion % Test,
"com.fasterxml.jackson.datatype" % "jackson-datatype-jdk8" % jacksonVersion % Test,
"com.fasterxml.jackson.module" % "jackson-module-jsonSchema" % jacksonJsonSchemaVersion % Test,
"io.swagger" % "swagger-core" % "1.6.2" % Test,
"org.scalatest" %% "scalatest" % "3.2.3" % Test
"org.scalatest" %% "scalatest" % "3.2.5" % Test
)

// build.properties
Expand Down

This file was deleted.

This file was deleted.

Expand Up @@ -15,6 +15,20 @@ object PositiveLong {
def apply(str: String): PositiveLong = new PositiveLong(str.toLong)
}

// Minimal reproducing class for the first failure case.
// The `apply` methods have the same _parameter names_, which causes:
// Conflicting property-based creators: already had explicitly marked creator [method regression.ConflictingJsonCreator#apply(long)],
// encountered another: [method regression.ConflictingJsonCreator#apply(java.lang.String)]
class ConflictingJsonCreator private (val value: Long) {
override def toString() = s"ConflictingJsonCreator($value)"
}
object ConflictingJsonCreator {
@JsonCreator
def apply(value: Long): ConflictingJsonCreator = new ConflictingJsonCreator(value)
@JsonCreator
def apply(value: String): ConflictingJsonCreator = new ConflictingJsonCreator(value.toLong)
}

object CreatorTest
{
class CreatorTestBean(val a: String, var b: String)
Expand Down Expand Up @@ -163,4 +177,17 @@ class CreatorTest extends DeserializationFixture {
val node: JsonNode = f.valueToTree[IntNode](10)
f.convertValue(node, new TypeReference[PositiveLong] {}).value shouldEqual node.asLong()
}

it should "support multiple creator annotations with the same parameter names" in { f =>
val node: JsonNode = f.valueToTree[IntNode](10)
// Ensure that the parameters are actually named `value`
ConflictingJsonCreator(value=10L).value shouldEqual node.asLong()
ConflictingJsonCreator(value="10").value shouldEqual node.asLong()
f.convertValue(node, new TypeReference[ConflictingJsonCreator] {}).value shouldEqual node.asLong()
}

it should "not have a problem constructors and member name conflicts" in { f =>
val node: JsonNode = f.valueToTree[IntNode](10)
f.convertValue(node, new TypeReference[PositiveLong] {}).value shouldEqual node.asLong()
}
}

0 comments on commit 3fa3ad5

Please sign in to comment.