@@ -1062,21 +1062,28 @@ private void _addCreatorParams(Map<String, POJOPropertyBuilder> props,
10621062 final boolean hasExplicit = (explName != null );
10631063 final POJOPropertyBuilder prop ;
10641064
1065- // neither implicit nor explicit name?
1066- if (!hasExplicit && (implName == null )) {
1067- boolean isUnwrapping = _annotationIntrospector .findUnwrappingNameTransformer (_config , param ) != null ;
1068-
1069- if (isUnwrapping ) {
1070- // If unwrapping, can use regardless of name; we will use a placeholder name
1071- // anyway to try to avoid name conflicts.
1065+ // [databind#5115] Resolve @JsonUnwrapped by checking the parameter first, then falling back to its field.
1066+ final String implNameStr = (implName != null ) ? implName .getSimpleName () : null ;
1067+ final POJOPropertyBuilder existingProp = (implNameStr != null ) ? props .get (implNameStr ) : null ;
1068+ final AnnotatedField field = (existingProp != null ) ? existingProp .getField () : null ;
1069+
1070+ // [databind#5115] Determine whether the creator parameter should be treated as unwrapped.
1071+ final boolean isUnwrapping =
1072+ _annotationIntrospector .findUnwrappingNameTransformer (_config , param ) != null ||
1073+ (field != null && _annotationIntrospector .findUnwrappingNameTransformer (_config , field ) != null );
1074+
1075+ if (isUnwrapping ) {
1076+ // [databind#5115] Serialization: Reuse the existing property, Deserialization: Use a placeholder creator property
1077+ if (_forSerialization && existingProp != null ) {
1078+ existingProp .addCtor (param , implName , hasExplicit , true , false );
1079+ prop = existingProp ;
1080+ } else {
10721081 PropertyName name = UnwrappedPropertyHandler .creatorParamName (param .getIndex ());
10731082 prop = _property (props , name );
1074- prop .addCtor (param , name , false , true , false );
1075- } else {
1076- // Without name, cannot make use of this creator parameter -- may or may not
1077- // be a problem, verified at a later point.
1078- prop = null ;
1083+ prop .addCtor (param , name , hasExplicit , true , false );
10791084 }
1085+ } else if (!hasExplicit && (implName == null )) {
1086+ prop = null ;
10801087 } else {
10811088 // 27-Dec-2019, tatu: [databind#2527] may need to rename according to field
10821089 if (implName != null ) {
0 commit comments