Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1062,21 +1062,28 @@ private void _addCreatorParams(Map<String, POJOPropertyBuilder> props,
final boolean hasExplicit = (explName != null);
final POJOPropertyBuilder prop;

// neither implicit nor explicit name?
if (!hasExplicit && (implName == null)) {
boolean isUnwrapping = _annotationIntrospector.findUnwrappingNameTransformer(_config, param) != null;

if (isUnwrapping) {
// If unwrapping, can use regardless of name; we will use a placeholder name
// anyway to try to avoid name conflicts.
// [databind#5115] Resolve @JsonUnwrapped by checking the parameter first, then falling back to its field.
final String implNameStr = (implName != null) ? implName.getSimpleName() : null;
final POJOPropertyBuilder existingProp = (implNameStr != null) ? props.get(implNameStr) : null;
final AnnotatedField field = (existingProp != null) ? existingProp.getField() : null;

// [databind#5115] Determine whether the creator parameter should be treated as unwrapped.
final boolean isUnwrapping =
_annotationIntrospector.findUnwrappingNameTransformer(_config, param) != null ||
(field != null && _annotationIntrospector.findUnwrappingNameTransformer(_config, field) != null);

if (isUnwrapping) {
// [databind#5115] Serialization: Reuse the existing property, Deserialization: Use a placeholder creator property
if (_forSerialization && existingProp != null) {
existingProp.addCtor(param, implName, hasExplicit, true, false);
prop = existingProp;
} else {
PropertyName name = UnwrappedPropertyHandler.creatorParamName(param.getIndex());
prop = _property(props, name);
prop.addCtor(param, name, false, true, false);
} else {
// Without name, cannot make use of this creator parameter -- may or may not
// be a problem, verified at a later point.
prop = null;
prop.addCtor(param, name, hasExplicit, true, false);
}
} else if (!hasExplicit && (implName == null)) {
prop = null;
} else {
// 27-Dec-2019, tatu: [databind#2527] may need to rename according to field
if (implName != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package tools.jackson.databind.records.tofix;
package tools.jackson.databind.records;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.annotation.JsonUnwrapped;
import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.testutil.DatabindTestUtil;
import tools.jackson.databind.testutil.failure.JacksonTestFailureExpected;

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

Expand Down Expand Up @@ -62,7 +61,6 @@ void unwrappedRecordShouldRoundTripPass() throws Exception
assertEquals(input, output);
}

@JacksonTestFailureExpected
@Test
void unwrappedRecordShouldRoundTrip() throws Exception
{
Expand Down