Skip to content

Commit 7ccfc9e

Browse files
authored
Fix #5115 (#5466)
1 parent a4af2a2 commit 7ccfc9e

File tree

4 files changed

+36
-21
lines changed

4 files changed

+36
-21
lines changed

release-notes/CREDITS

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,15 @@ Oliver Drotbohm (@odrotbohm)
127127
* Contributed fix for #4629: `@JsonIncludeProperties` and `@JsonIgnoreProperties`
128128
ignored when deserializing Records
129129
[3.1.0]
130-
130+
* Contributed fix for #5115: `@JsonUnwrapped` Record deserialization can't handle
131+
name collision
132+
[3.1.0]
133+
134+
Viktor Szathmáry (@phraktle)
135+
* Reported #5115: `@JsonUnwrapped` Record deserialization can't handle name collision
136+
(reported by Viktor S)
137+
[3.1.0]
138+
131139
Hélios Gilles (@RoiSoleil)
132140
* Contributed #5413: Add/support forward reference resolution for array values
133141
[3.1.0]

release-notes/VERSION

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ Versions: 3.x (for earlier see VERSION-2.x)
2424
creator property" when deserializing JSON with dup property to single-property Record
2525
(reported by @sseelmann)
2626
(fix contributed by @JacksonJang)
27+
#5115: `@JsonUnwrapped` Record deserialization can't handle name collision
28+
(reported by Viktor S)
29+
(fix contributed by @JacksonJang)
2730
#5184: `@JsonIgnore` on record method applied to record matching field
2831
at deserialization
2932
(reported by @emouty)

src/main/java/tools/jackson/databind/introspect/POJOPropertiesCollector.java

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,33 +1054,38 @@ private void _addCreatorParams(Map<String, POJOPropertyBuilder> props,
10541054
final PropertyName explName = ctor.explicitName(i);
10551055
PropertyName implName = ctor.implicitName(i);
10561056
final boolean hasExplicit = (explName != null);
1057-
final POJOPropertyBuilder prop;
1058-
1059-
// neither implicit nor explicit name?
1060-
if (!hasExplicit && (implName == null)) {
1061-
boolean isUnwrapping = _annotationIntrospector.findUnwrappingNameTransformer(_config, param) != null;
1057+
final boolean hasImplicit = (implName != null);
10621058

1063-
if (isUnwrapping) {
1059+
// First: check "Unwrapped" unless explicit name
1060+
if (!hasExplicit) {
1061+
var unwrapper = _annotationIntrospector.findUnwrappingNameTransformer(_config, param);
1062+
if (unwrapper != null) {
10641063
// If unwrapping, can use regardless of name; we will use a placeholder name
10651064
// anyway to try to avoid name conflicts.
10661065
PropertyName name = UnwrappedPropertyHandler.creatorParamName(param.getIndex());
1067-
prop = _property(props, name);
1066+
final POJOPropertyBuilder prop = _property(props, name);
10681067
prop.addCtor(param, name, false, true, false);
1069-
} else {
1068+
creatorProps.add(prop);
1069+
continue;
1070+
}
1071+
if (!hasImplicit) {
10701072
// Without name, cannot make use of this creator parameter -- may or may not
10711073
// be a problem, verified at a later point.
1072-
prop = null;
1074+
creatorProps.add(null);
1075+
continue;
10731076
}
1077+
}
1078+
1079+
// 27-Dec-2019, tatu: [databind#2527] may need to rename according to field
1080+
final POJOPropertyBuilder prop;
1081+
if (hasImplicit) {
1082+
String n = _checkRenameByField(implName.getSimpleName());
1083+
implName = PropertyName.construct(n);
1084+
prop = _property(props, implName);
10741085
} else {
1075-
// 27-Dec-2019, tatu: [databind#2527] may need to rename according to field
1076-
if (implName != null) {
1077-
String n = _checkRenameByField(implName.getSimpleName());
1078-
implName = PropertyName.construct(n);
1079-
}
1080-
prop = (implName == null)
1081-
? _property(props, explName) : _property(props, implName);
1082-
prop.addCtor(param, hasExplicit ? explName : implName, hasExplicit, true, false);
1086+
prop = _property(props, explName);
10831087
}
1088+
prop.addCtor(param, hasExplicit ? explName : implName, hasExplicit, true, false);
10841089
creatorProps.add(prop);
10851090
}
10861091
ctor.assignPropertyDefs(creatorProps);

src/test/java/tools/jackson/databind/records/tofix/RecordUnwrapped5115Test.java renamed to src/test/java/tools/jackson/databind/records/RecordUnwrapped5115Test.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
package tools.jackson.databind.records.tofix;
1+
package tools.jackson.databind.records;
22

33
import org.junit.jupiter.api.Test;
44

55
import com.fasterxml.jackson.annotation.JsonUnwrapped;
6+
67
import tools.jackson.databind.ObjectMapper;
78
import tools.jackson.databind.testutil.DatabindTestUtil;
8-
import tools.jackson.databind.testutil.failure.JacksonTestFailureExpected;
99

1010
import static org.junit.jupiter.api.Assertions.assertEquals;
1111

@@ -62,7 +62,6 @@ void unwrappedRecordShouldRoundTripPass() throws Exception
6262
assertEquals(input, output);
6363
}
6464

65-
@JacksonTestFailureExpected
6665
@Test
6766
void unwrappedRecordShouldRoundTrip() throws Exception
6867
{

0 commit comments

Comments
 (0)