20
20
import java .lang .reflect .Field ;
21
21
import java .util .Collection ;
22
22
import java .util .Collections ;
23
+ import java .util .HashMap ;
23
24
import java .util .Map ;
24
25
import java .util .Optional ;
25
26
@@ -297,6 +298,7 @@ private Map<?, Object> bindMapToMap(
297
298
private @ Nullable Object bindViaConstructorAndSetters (Constructor <?> constructor ,
298
299
Map <String , Object > rawMap , ResolvableType ownerType , ArgumentsBindingResult bindingResult ) {
299
300
301
+ Map <String , Object > dataToBind = new HashMap <>(rawMap );
300
302
@ Nullable String [] paramNames = BeanUtils .getParameterNames (constructor );
301
303
Class <?>[] paramTypes = constructor .getParameterTypes ();
302
304
@ Nullable Object [] constructorArguments = new Object [paramTypes .length ];
@@ -308,14 +310,16 @@ private Map<?, Object> bindMapToMap(
308
310
ResolvableType targetType = ResolvableType .forType (
309
311
ResolvableType .forConstructorParameter (constructor , i ).getType (), ownerType );
310
312
311
- Object rawValue = rawMap .get (name );
312
- boolean isNotPresent = !rawMap .containsKey (name );
313
+ Object rawValue = dataToBind .get (name );
314
+ boolean isNotPresent = !dataToBind .containsKey (name );
315
+ dataToBind .remove (name );
313
316
314
317
if (rawValue == null && this .nameResolver != null ) {
315
- for (String key : rawMap .keySet ()) {
318
+ for (String key : dataToBind .keySet ()) {
316
319
if (this .nameResolver .resolveName (key ).equals (name )) {
317
- rawValue = rawMap .get (key );
320
+ rawValue = dataToBind .get (key );
318
321
isNotPresent = false ;
322
+ dataToBind .remove (key );
319
323
break ;
320
324
}
321
325
}
@@ -337,9 +341,9 @@ private Map<?, Object> bindMapToMap(
337
341
throw ex ;
338
342
}
339
343
340
- // If no errors, apply setters too
341
- if (!bindingResult .hasErrors ()) {
342
- bindViaSetters (target , rawMap , ownerType , bindingResult );
344
+ // If no errors and data remains to be bound , apply setters too
345
+ if (!dataToBind . isEmpty () && ! bindingResult .hasErrors ()) {
346
+ bindViaSetters (target , dataToBind , ownerType , bindingResult );
343
347
}
344
348
345
349
return target ;
0 commit comments