Browse Source

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.
pull/1382/head
Rossen Stoyanchev 9 years ago
parent
commit
91977c81ad
  1. 3
      spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestParamMethodArgumentResolver.java
  2. 10
      spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingViewResolutionIntegrationTests.java

3
spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestParamMethodArgumentResolver.java

@ -82,7 +82,8 @@ public class RequestParamMethodArgumentResolver extends AbstractNamedValueSyncAr @@ -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;
}

10
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingViewResolutionIntegrationTests.java

@ -22,7 +22,6 @@ import java.net.URI; @@ -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; @@ -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 @@ -126,9 +124,7 @@ public class RequestMappingViewResolutionIntegrationTests extends AbstractReques
private static class TestController {
@GetMapping("/html")
public String getHtmlPage(@RequestParam Optional<String> name, Model model,
ServerWebExchange exchange) {
public String getHtmlPage(Optional<String> name, Model model, ServerWebExchange exchange) {
if (exchange.checkNotModified("deadb33f8badf00d")) {
return null;
}
@ -137,8 +133,8 @@ public class RequestMappingViewResolutionIntegrationTests extends AbstractReques @@ -137,8 +133,8 @@ public class RequestMappingViewResolutionIntegrationTests extends AbstractReques
}
@GetMapping("/redirect")
public Mono<String> redirect() {
return Mono.just("redirect:/");
public String redirect() {
return "redirect:/";
}
}

Loading…
Cancel
Save