From 91977c81adf34abc23fc61ee6d31cb4560c32293 Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Fri, 7 Apr 2017 16:51:55 -0400 Subject: [PATCH] Support Optional without @RequestParam in WebFlux The java.util.Optional wrapper should not affect the support for "request param" arguments with or without the annotation as it works on the Spring MVC side. --- .../annotation/RequestParamMethodArgumentResolver.java | 3 ++- .../RequestMappingViewResolutionIntegrationTests.java | 10 +++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestParamMethodArgumentResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestParamMethodArgumentResolver.java index c75f0819d10..703618cf936 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestParamMethodArgumentResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestParamMethodArgumentResolver.java @@ -82,7 +82,8 @@ public class RequestParamMethodArgumentResolver extends AbstractNamedValueSyncAr return true; } else if (this.useDefaultResolution) { - return checkParameterTypeNoReactiveWrapper(param, BeanUtils::isSimpleProperty); + return checkParameterTypeNoReactiveWrapper(param, BeanUtils::isSimpleProperty) || + BeanUtils.isSimpleProperty(param.nestedIfOptional().getNestedParameterType()); } return false; } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingViewResolutionIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingViewResolutionIntegrationTests.java index ceab6666d6c..e9053df21fc 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingViewResolutionIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingViewResolutionIntegrationTests.java @@ -22,7 +22,6 @@ import java.net.URI; import java.util.Optional; import org.junit.Test; -import reactor.core.publisher.Mono; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; @@ -37,7 +36,6 @@ import org.springframework.http.client.SimpleClientHttpRequestFactory; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.client.RestTemplate; import org.springframework.web.reactive.config.EnableWebFlux; import org.springframework.web.reactive.config.ViewResolverRegistry; @@ -126,9 +124,7 @@ public class RequestMappingViewResolutionIntegrationTests extends AbstractReques private static class TestController { @GetMapping("/html") - public String getHtmlPage(@RequestParam Optional name, Model model, - ServerWebExchange exchange) { - + public String getHtmlPage(Optional name, Model model, ServerWebExchange exchange) { if (exchange.checkNotModified("deadb33f8badf00d")) { return null; } @@ -137,8 +133,8 @@ public class RequestMappingViewResolutionIntegrationTests extends AbstractReques } @GetMapping("/redirect") - public Mono redirect() { - return Mono.just("redirect:/"); + public String redirect() { + return "redirect:/"; } }