Skip to content

Commit 91977c8

Browse files
committed
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.
1 parent 3780d04 commit 91977c8

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ public boolean supportsParameter(MethodParameter param) {
8282
return true;
8383
}
8484
else if (this.useDefaultResolution) {
85-
return checkParameterTypeNoReactiveWrapper(param, BeanUtils::isSimpleProperty);
85+
return checkParameterTypeNoReactiveWrapper(param, BeanUtils::isSimpleProperty) ||
86+
BeanUtils.isSimpleProperty(param.nestedIfOptional().getNestedParameterType());
8687
}
8788
return false;
8889
}

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import java.util.Optional;
2323

2424
import org.junit.Test;
25-
import reactor.core.publisher.Mono;
2625

2726
import org.springframework.context.ApplicationContext;
2827
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
@@ -37,7 +36,6 @@
3736
import org.springframework.stereotype.Controller;
3837
import org.springframework.ui.Model;
3938
import org.springframework.web.bind.annotation.GetMapping;
40-
import org.springframework.web.bind.annotation.RequestParam;
4139
import org.springframework.web.client.RestTemplate;
4240
import org.springframework.web.reactive.config.EnableWebFlux;
4341
import org.springframework.web.reactive.config.ViewResolverRegistry;
@@ -126,9 +124,7 @@ public FreeMarkerConfigurer freeMarkerConfig() {
126124
private static class TestController {
127125

128126
@GetMapping("/html")
129-
public String getHtmlPage(@RequestParam Optional<String> name, Model model,
130-
ServerWebExchange exchange) {
131-
127+
public String getHtmlPage(Optional<String> name, Model model, ServerWebExchange exchange) {
132128
if (exchange.checkNotModified("deadb33f8badf00d")) {
133129
return null;
134130
}
@@ -137,8 +133,8 @@ public String getHtmlPage(@RequestParam Optional<String> name, Model model,
137133
}
138134

139135
@GetMapping("/redirect")
140-
public Mono<String> redirect() {
141-
return Mono.just("redirect:/");
136+
public String redirect() {
137+
return "redirect:/";
142138
}
143139
}
144140

0 commit comments

Comments
 (0)