@@ -7,14 +7,30 @@ import com.fasterxml.jackson.databind.node.IntNode
7
7
import org .junit .runner .RunWith
8
8
import org .scalatestplus .junit .JUnitRunner
9
9
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) "
12
16
}
13
- object PositiveLong {
17
+ object ConflictingJsonCreator {
14
18
@ JsonCreator
15
- def apply (long : Long ): PositiveLong = new PositiveLong (long )
19
+ def apply (value : Long ): ConflictingJsonCreator = new ConflictingJsonCreator (value )
16
20
@ 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)
18
34
}
19
35
20
36
object CreatorTest
@@ -166,8 +182,17 @@ class CreatorTest extends DeserializationFixture {
166
182
f.writeValueAsString(ConstructorWithOptionStruct ()) shouldEqual """ {"s":null}"""
167
183
}
168
184
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 =>
170
194
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()
172
197
}
173
198
}
0 commit comments