Skip to content

Commit 53f3469

Browse files
authored
Fix #4908 (#4924)
1 parent 5b1b9ab commit 53f3469

File tree

4 files changed

+42
-3
lines changed

4 files changed

+42
-3
lines changed

release-notes/CREDITS-2.x

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1868,3 +1868,8 @@ Tomáš Poledný (@Saljack)
18681868
* Reported #4860: `ConstructorDetector.USE_PROPERTIES_BASED` does not work with
18691869
multiple constructors since 2.18
18701870
(2.18.3)
1871+
1872+
Gustavo Bazan (@gssbzn)
1873+
* Reported #4908: Deserialization behavior change with @JsonCreator and
1874+
@ConstructorProperties between 2.17 and 2.18
1875+
(2.18.3)

release-notes/VERSION-2.x

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ Project: jackson-databind
1818
multiple constructors since 2.18
1919
(reported by Tomáš P)
2020
(fix by Joo-Hyuk K, @cowtowncoder)
21+
#4908: Deserialization behavior change with @JsonCreator and
22+
@ConstructorProperties between 2.17 and 2.18
23+
(reported by Gustavo B)
2124

2225
2.18.2 (27-Nov-2024)
2326

src/main/java/com/fasterxml/jackson/databind/introspect/JacksonAnnotationIntrospector.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,8 +1486,16 @@ public JsonCreator.Mode findCreatorBinding(Annotated a) {
14861486
@Override
14871487
public JsonCreator.Mode findCreatorAnnotation(MapperConfig<?> config, Annotated a) {
14881488
JsonCreator ann = _findAnnotation(a, JsonCreator.class);
1489-
if (ann != null) {
1490-
return ann.mode();
1489+
JsonCreator.Mode mode;
1490+
if (ann == null) {
1491+
mode = null;
1492+
} else {
1493+
mode = ann.mode();
1494+
// 25-Jan-2025, tatu: [databind#4809] Need to avoid "DEFAULT" from masking
1495+
// @CreatorProperties-provided value
1496+
if (mode != JsonCreator.Mode.DEFAULT) {
1497+
return mode;
1498+
}
14911499
}
14921500
if (_cfgConstructorPropertiesImpliesCreator
14931501
&& config.isEnabled(MapperFeature.INFER_CREATOR_FROM_CONSTRUCTOR_PROPERTIES)
@@ -1503,7 +1511,7 @@ public JsonCreator.Mode findCreatorAnnotation(MapperConfig<?> config, Annotated
15031511
}
15041512
}
15051513
}
1506-
return null;
1514+
return mode;
15071515
}
15081516

15091517
/*

src/test/java/com/fasterxml/jackson/databind/deser/creators/CreatorPropertiesTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,27 @@ public void testSkipNonScalar3252() throws Exception
147147
//System.err.println("JsON: "+MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(testData));
148148
assertEquals(3, testData.size());
149149
}
150+
151+
static class Something4908 {
152+
@JsonProperty("value")
153+
private final String _value;
154+
155+
String getValue() {
156+
return _value;
157+
}
158+
159+
@JsonCreator
160+
@ConstructorProperties({"value"})
161+
Something4908(String pValue) {
162+
_value = pValue;
163+
}
164+
}
165+
166+
// [databind#4908] @ConstructorProperties and @JsonCreator
167+
@Test
168+
public void testConstructorPropertyAndJsonCreator() throws Exception {
169+
Something4908 value = MAPPER.readValue(a2q("{'value':'abc'}"),
170+
Something4908.class);
171+
assertEquals("abc", value.getValue());
172+
}
150173
}

0 commit comments

Comments
 (0)