Unwrap Optional for @RequestParam reverse resolution

Closes gh-22656
This commit is contained in:
Rossen Stoyanchev
2019-04-18 22:40:12 -04:00
parent 4e63153886
commit c09e711eb2
2 changed files with 23 additions and 2 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@ import java.beans.PropertyEditor;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.Part;
@@ -217,6 +218,11 @@ public class RequestParamMethodArgumentResolver extends AbstractNamedValueMethod
parameter.getParameterName() : requestParam.name());
Assert.state(name != null, "Unresolvable parameter name");
parameter = parameter.nestedIfOptional();
if (value instanceof Optional) {
value = ((Optional<?>) value).orElse(null);
}
if (value == null) {
if (requestParam != null &&
(!requestParam.required() || !requestParam.defaultValue().equals(ValueConstants.DEFAULT_NONE))) {