Skip to content

Commit 8fa0990

Browse files
Fully representing regression test for #505 (#508)
* Fully representing regression test for #505 * Splitting out the individual concerns instead of overloading the test
1 parent efd53d2 commit 8fa0990

File tree

1 file changed

+32
-7
lines changed

1 file changed

+32
-7
lines changed

Diff for: src/test/scala/com/fasterxml/jackson/module/scala/deser/CreatorTest.scala

+32-7
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,30 @@ import com.fasterxml.jackson.databind.node.IntNode
77
import org.junit.runner.RunWith
88
import org.scalatestplus.junit.JUnitRunner
99

10-
class PositiveLong private (val value: Long) {
11-
override def toString() = s"PositiveLong($value)"
10+
// Minimal reproducing class for the first failure case.
11+
// The `apply` methods have the same _parameter names_, which causes:
12+
// Conflicting property-based creators: already had explicitly marked creator [method regression.ConflictingJsonCreator#apply(long)],
13+
// encountered another: [method regression.ConflictingJsonCreator#apply(java.lang.String)]
14+
class ConflictingJsonCreator private (val value: Long) {
15+
override def toString() = s"ConflictingJsonCreator($value)"
1216
}
13-
object PositiveLong {
17+
object ConflictingJsonCreator {
1418
@JsonCreator
15-
def apply(long: Long): PositiveLong = new PositiveLong(long)
19+
def apply(value: Long): ConflictingJsonCreator = new ConflictingJsonCreator(value)
1620
@JsonCreator
17-
def apply(str: String): PositiveLong = new PositiveLong(str.toLong)
21+
def apply(value: String): ConflictingJsonCreator = new ConflictingJsonCreator(value.toLong)
22+
}
23+
24+
// Minimal reproducing class for the second failure case.
25+
// The `apply` method has the same parameter name as the value class's _member_, which causes:
26+
// Cannot construct instance of `regression.ConflictingMember` (although at least one Creator exists):
27+
// no int/Int-argument constructor/factory method to deserialize from Number value (10)
28+
class ConflictingMember private (val value: Long) {
29+
override def toString() = s"ConflictingMember($value)"
30+
}
31+
object ConflictingMember {
32+
@JsonCreator
33+
def apply(value: Long): ConflictingMember = new ConflictingMember(value)
1834
}
1935

2036
object CreatorTest
@@ -166,8 +182,17 @@ class CreatorTest extends DeserializationFixture {
166182
f.writeValueAsString(ConstructorWithOptionStruct()) shouldEqual """{"s":null}"""
167183
}
168184

169-
it should "support multiple creator annotations" in { f =>
185+
it should "support multiple creator annotations with the same parameter names" in { f =>
186+
val node: JsonNode = f.valueToTree[IntNode](10)
187+
// Ensure that the parameters are actually named `value`
188+
ConflictingJsonCreator(value=10L).value shouldEqual 10L
189+
ConflictingJsonCreator(value="10").value shouldEqual 10L
190+
f.convertValue(node, new TypeReference[ConflictingJsonCreator] {}).value shouldEqual node.asLong()
191+
}
192+
193+
it should "not have a problem constructors and member name conflicts" in { f =>
170194
val node: JsonNode = f.valueToTree[IntNode](10)
171-
f.convertValue(node, new TypeReference[PositiveLong] {}).value shouldEqual node.asLong()
195+
ConflictingMember(value=10L).value shouldEqual 10L
196+
f.convertValue(node, new TypeReference[ConflictingMember] {}).value shouldEqual node.asLong()
172197
}
173198
}

0 commit comments

Comments
 (0)