Skip to content

Issue 505 test (2.12) #509

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

Closed
Closed
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
Expand Up @@ -5,14 +5,30 @@ 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)"
// 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 PositiveLong {
object ConflictingJsonCreator {
@JsonCreator
def apply(long: Long): PositiveLong = new PositiveLong(long)
def apply(value: Long): ConflictingJsonCreator = new ConflictingJsonCreator(value)
@JsonCreator
def apply(str: String): PositiveLong = new PositiveLong(str.toLong)
def apply(value: String): ConflictingJsonCreator = new ConflictingJsonCreator(value.toLong)
}

// Minimal reproducing class for the second failure case.
// The `apply` method has the same parameter name as the value class's _member_, which causes:
// Cannot construct instance of `regression.ConflictingMember` (although at least one Creator exists):
// no int/Int-argument constructor/factory method to deserialize from Number value (10)
class ConflictingMember private (val value: Long) {
override def toString() = s"ConflictingMember($value)"
}
object ConflictingMember {
@JsonCreator
def apply(value: Long): ConflictingMember = new ConflictingMember(value)
}

object CreatorTest
Expand Down Expand Up @@ -159,8 +175,17 @@ class CreatorTest extends DeserializationFixture {
f.writeValueAsString(ConstructorWithOptionStruct()) shouldEqual """{"s":null}"""
}

it should "support multiple creator annotations" in { f =>
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 10L
ConflictingJsonCreator(value="10").value shouldEqual 10L
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()
ConflictingMember(value=10L).value shouldEqual 10L
f.convertValue(node, new TypeReference[ConflictingMember] {}).value shouldEqual node.asLong()
}
}