|
22 | 22 | import java.lang.reflect.Field;
|
23 | 23 | import java.util.ArrayList;
|
24 | 24 | import java.util.Arrays;
|
| 25 | +import java.util.Collection; |
25 | 26 | import java.util.Collections;
|
26 | 27 | import java.util.HashMap;
|
27 | 28 | import java.util.HashSet;
|
@@ -947,7 +948,7 @@ private Object createObject(ResolvableType objectType, String nestedPath, ValueR
|
947 | 948 | Class<?> paramType = paramTypes[i];
|
948 | 949 | Object value = valueResolver.resolveValue(paramPath, paramType);
|
949 | 950 |
|
950 |
| - if (value == null && !BeanUtils.isSimpleValueType(param.nestedIfOptional().getNestedParameterType())) { |
| 951 | + if (value == null && shouldCreateObject(param)) { |
951 | 952 | ResolvableType type = ResolvableType.forMethodParameter(param);
|
952 | 953 | args[i] = createObject(type, paramPath + ".", valueResolver);
|
953 | 954 | }
|
@@ -1007,6 +1008,12 @@ private Object createObject(ResolvableType objectType, String nestedPath, ValueR
|
1007 | 1008 | return (isOptional && !nestedPath.isEmpty() ? Optional.ofNullable(result) : result);
|
1008 | 1009 | }
|
1009 | 1010 |
|
| 1011 | + private static boolean shouldCreateObject(MethodParameter param) { |
| 1012 | + Class<?> type = param.nestedIfOptional().getNestedParameterType(); |
| 1013 | + return !(BeanUtils.isSimpleValueType(type) || |
| 1014 | + Collection.class.isAssignableFrom(type) || Map.class.isAssignableFrom(type) || type.isArray()); |
| 1015 | + } |
| 1016 | + |
1010 | 1017 | private void validateConstructorArgument(
|
1011 | 1018 | Class<?> constructorClass, String nestedPath, String name, @Nullable Object value) {
|
1012 | 1019 |
|
|
0 commit comments