Skip to content

Commit

Permalink
Fix #4908 (#4924)
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder authored Jan 26, 2025
1 parent 5b1b9ab commit 53f3469
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
5 changes: 5 additions & 0 deletions release-notes/CREDITS-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -1868,3 +1868,8 @@ Tomáš Poledný (@Saljack)
* Reported #4860: `ConstructorDetector.USE_PROPERTIES_BASED` does not work with
multiple constructors since 2.18
(2.18.3)

Gustavo Bazan (@gssbzn)
* Reported #4908: Deserialization behavior change with @JsonCreator and
@ConstructorProperties between 2.17 and 2.18
(2.18.3)
3 changes: 3 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ Project: jackson-databind
multiple constructors since 2.18
(reported by Tomáš P)
(fix by Joo-Hyuk K, @cowtowncoder)
#4908: Deserialization behavior change with @JsonCreator and
@ConstructorProperties between 2.17 and 2.18
(reported by Gustavo B)

2.18.2 (27-Nov-2024)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1486,8 +1486,16 @@ public JsonCreator.Mode findCreatorBinding(Annotated a) {
@Override
public JsonCreator.Mode findCreatorAnnotation(MapperConfig<?> config, Annotated a) {
JsonCreator ann = _findAnnotation(a, JsonCreator.class);
if (ann != null) {
return ann.mode();
JsonCreator.Mode mode;
if (ann == null) {
mode = null;
} else {
mode = ann.mode();
// 25-Jan-2025, tatu: [databind#4809] Need to avoid "DEFAULT" from masking
// @CreatorProperties-provided value
if (mode != JsonCreator.Mode.DEFAULT) {
return mode;
}
}
if (_cfgConstructorPropertiesImpliesCreator
&& config.isEnabled(MapperFeature.INFER_CREATOR_FROM_CONSTRUCTOR_PROPERTIES)
Expand All @@ -1503,7 +1511,7 @@ public JsonCreator.Mode findCreatorAnnotation(MapperConfig<?> config, Annotated
}
}
}
return null;
return mode;
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,27 @@ public void testSkipNonScalar3252() throws Exception
//System.err.println("JsON: "+MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(testData));
assertEquals(3, testData.size());
}

static class Something4908 {
@JsonProperty("value")
private final String _value;

String getValue() {
return _value;
}

@JsonCreator
@ConstructorProperties({"value"})
Something4908(String pValue) {
_value = pValue;
}
}

// [databind#4908] @ConstructorProperties and @JsonCreator
@Test
public void testConstructorPropertyAndJsonCreator() throws Exception {
Something4908 value = MAPPER.readValue(a2q("{'value':'abc'}"),
Something4908.class);
assertEquals("abc", value.getValue());
}
}

0 comments on commit 53f3469

Please sign in to comment.