Allow treating empty @RequestParam as missing value
If type conversion turns an empty request parameter value (i.e. "") to null, we should treat it as a missing value. By default the ConversionService doesn't change empty strings and therefore one must explicitly convert them to null for example by registering a StringTrimmerEditor with emptyAsNull=true. Issue: SPR-10402
This commit is contained in:
@@ -74,6 +74,7 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle
|
||||
this.expressionContext = (beanFactory != null) ? new BeanExpressionContext(beanFactory, new RequestScope()) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Object resolveArgument(
|
||||
MethodParameter parameter, ModelAndViewContainer mavContainer,
|
||||
NativeWebRequest webRequest, WebDataBinderFactory binderFactory)
|
||||
@@ -96,11 +97,17 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle
|
||||
arg = resolveDefaultValue(namedValueInfo.defaultValue);
|
||||
}
|
||||
|
||||
boolean emptyArgValue = "".equals(arg);
|
||||
|
||||
if (binderFactory != null) {
|
||||
WebDataBinder binder = binderFactory.createBinder(webRequest, null, namedValueInfo.name);
|
||||
arg = binder.convertIfNecessary(arg, paramType, parameter);
|
||||
}
|
||||
|
||||
if (emptyArgValue && (arg == null)) {
|
||||
handleMissingValue(namedValueInfo.name, parameter);
|
||||
}
|
||||
|
||||
handleResolvedValue(arg, namedValueInfo.name, parameter, mavContainer, webRequest);
|
||||
|
||||
return arg;
|
||||
|
||||
Reference in New Issue
Block a user