Skip to content

Commit 296d90c

Browse files
committed
Add a passing test for #4545
1 parent c524eae commit 296d90c

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

release-notes/CREDITS-2.x

+5
Original file line numberDiff line numberDiff line change
@@ -1791,3 +1791,8 @@ Teodor Danciu (teodord@github)
17911791
Matthew Luckam (mluckam@github)
17921792
* Contributed #4483: Remove `final` on method BeanSerializer.serialize()
17931793
(2.18.0)
1794+
1795+
Alexandre Jacob (ajacob@github)
1796+
* Reported #4545: Unexpected deserialization behavior with `@JsonCreator`,
1797+
`@JsonProperty` and javac `-parameters`
1798+
(2.18.0)

release-notes/VERSION-2.x

+3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ Project: jackson-databind
3737
#4483: Remove `final` on method BeanSerializer.serialize()
3838
(contributed by Matthew L)
3939
#4515: Rewrite Bean Property Introspection logic in Jackson 2.x
40+
#4545: Unexpected deserialization behavior with `@JsonCreator`,
41+
`@JsonProperty` and javac `-parameters`
42+
(reported by Alexandre J)
4043

4144
2.17.1 (04-May-2024)
4245

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package com.fasterxml.jackson.databind.deser.creators;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import com.fasterxml.jackson.annotation.JsonCreator;
6+
import com.fasterxml.jackson.annotation.JsonProperty;
7+
8+
import com.fasterxml.jackson.databind.*;
9+
import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException;
10+
import com.fasterxml.jackson.databind.testutil.DatabindTestUtil;
11+
12+
import static org.junit.jupiter.api.Assertions.fail;
13+
14+
public class CreatorWithRenamedParam4545Test
15+
extends DatabindTestUtil
16+
{
17+
static class Payload4545 {
18+
private final String key1;
19+
private final String key2;
20+
21+
@JsonCreator
22+
public Payload4545(
23+
@ImplicitName("key1")
24+
@JsonProperty("key")
25+
String key1, // NOTE: the mismatch `key` / `key1` is important
26+
27+
@ImplicitName("key2")
28+
@JsonProperty("key2")
29+
String key2
30+
) {
31+
this.key1 = key1;
32+
this.key2 = key2;
33+
}
34+
35+
public String getKey1() {
36+
return key1;
37+
}
38+
39+
public String getKey2() {
40+
return key2;
41+
}
42+
}
43+
44+
private final ObjectMapper MAPPER = jsonMapperBuilder()
45+
.disable(MapperFeature.ALLOW_FINAL_FIELDS_AS_MUTATORS)
46+
.annotationIntrospector(new ImplicitNameIntrospector())
47+
.build();
48+
49+
// [databind#4545]
50+
@Test
51+
public void testCreatorWithRename4545() throws Exception
52+
{
53+
String jsonPayload = a2q("{ 'key1': 'val1', 'key2': 'val2'}");
54+
55+
try {
56+
MAPPER.readValue(jsonPayload, Payload4545.class);
57+
fail("Should not pass");
58+
} catch (UnrecognizedPropertyException e) {
59+
verifyException(e, "Unrecognized");
60+
verifyException(e, "key1");
61+
}
62+
}
63+
}

0 commit comments

Comments
 (0)