Treat Kotlin nullable as non-required

Where `isOptional` is used, also check for `isNullable` i.e.
values are not considered required if they are Kotlin nullables:
- spring-messaging: named value method arguments
- spring-web: named value method arguments
- spring-webmvc: request parts

This means that Kotlin client code no longer has to explicity specify
"required=false" for Kotlin nullables -- this information is inferred
automatically by the framework.

Issue: SPR-14165
This commit is contained in:
Raman Gupta
2016-09-08 14:06:01 -04:00
committed by Sebastien Deleuze
parent 735e288d46
commit fada91e538
7 changed files with 155 additions and 3 deletions

View File

@@ -98,7 +98,7 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle
if (namedValueInfo.defaultValue != null) {
arg = resolveStringValue(namedValueInfo.defaultValue);
}
else if (namedValueInfo.required && !nestedParameter.isOptional()) {
else if (namedValueInfo.required && !nestedParameter.isOptional() && !nestedParameter.isNullable()) {
handleMissingValue(namedValueInfo.name, nestedParameter, message);
}
arg = handleNullValue(namedValueInfo.name, arg, nestedParameter.getNestedParameterType());