Skip to content

Commit 8c39294

Browse files
committed
Merge branch '1.4.x'
2 parents a821a31 + aa8bb81 commit 8c39294

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

spring-graphql/src/main/java/org/springframework/graphql/data/GraphQlArgumentBinder.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.lang.reflect.Field;
2121
import java.util.Collection;
2222
import java.util.Collections;
23+
import java.util.HashMap;
2324
import java.util.Map;
2425
import java.util.Optional;
2526

@@ -297,6 +298,7 @@ private Map<?, Object> bindMapToMap(
297298
private @Nullable Object bindViaConstructorAndSetters(Constructor<?> constructor,
298299
Map<String, Object> rawMap, ResolvableType ownerType, ArgumentsBindingResult bindingResult) {
299300

301+
Map<String, Object> dataToBind = new HashMap<>(rawMap);
300302
@Nullable String[] paramNames = BeanUtils.getParameterNames(constructor);
301303
Class<?>[] paramTypes = constructor.getParameterTypes();
302304
@Nullable Object[] constructorArguments = new Object[paramTypes.length];
@@ -308,14 +310,16 @@ private Map<?, Object> bindMapToMap(
308310
ResolvableType targetType = ResolvableType.forType(
309311
ResolvableType.forConstructorParameter(constructor, i).getType(), ownerType);
310312

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);
313316

314317
if (rawValue == null && this.nameResolver != null) {
315-
for (String key : rawMap.keySet()) {
318+
for (String key : dataToBind.keySet()) {
316319
if (this.nameResolver.resolveName(key).equals(name)) {
317-
rawValue = rawMap.get(key);
320+
rawValue = dataToBind.get(key);
318321
isNotPresent = false;
322+
dataToBind.remove(key);
319323
break;
320324
}
321325
}
@@ -337,9 +341,9 @@ private Map<?, Object> bindMapToMap(
337341
throw ex;
338342
}
339343

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);
343347
}
344348

345349
return target;

0 commit comments

Comments
 (0)