Polish contribution
See gh-25200
This commit is contained in:
@@ -40,6 +40,7 @@ import org.springframework.beans.TypeMismatchException;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.validation.BindException;
|
||||
import org.springframework.validation.BindingResult;
|
||||
@@ -257,6 +258,14 @@ public class ModelAttributeMethodProcessor implements HandlerMethodArgumentResol
|
||||
String paramName = paramNames[i];
|
||||
Class<?> paramType = paramTypes[i];
|
||||
Object value = webRequest.getParameterValues(paramName);
|
||||
|
||||
// Since WebRequest#getParameter exposes a single-value parameter as an array
|
||||
// with a single element, we unwrap the single value in such cases, analogous
|
||||
// to WebExchangeDataBinder.addBindValue(Map<String, Object>, String, List<?>).
|
||||
if (ObjectUtils.isArray(value) && Array.getLength(value) == 1) {
|
||||
value = Array.get(value, 0);
|
||||
}
|
||||
|
||||
if (value == null) {
|
||||
if (fieldDefaultPrefix != null) {
|
||||
value = webRequest.getParameter(fieldDefaultPrefix + paramName);
|
||||
@@ -271,11 +280,6 @@ public class ModelAttributeMethodProcessor implements HandlerMethodArgumentResol
|
||||
}
|
||||
}
|
||||
|
||||
// Singular web parameters are wrapped with array, extract it so it can be picked up by conversion service later on
|
||||
if (value != null && value.getClass().isArray() && Array.getLength(value) == 1) {
|
||||
value = Array.get(value, 0);
|
||||
}
|
||||
|
||||
try {
|
||||
MethodParameter methodParam = new FieldAwareConstructorParameter(ctor, i, paramName);
|
||||
if (value == null && methodParam.isOptional()) {
|
||||
|
||||
Reference in New Issue
Block a user