Skip to content

Commit 21887ad

Browse files
mattbertolinijhoeller
authored andcommitted
Allow override of data binder binding
Motivation ---------- The Spring MVC ModelAttributeMethodProcessor includes many helpful extension methods that allow developers to extend and enhance the data binding capabilities of the class. Unfortunately, Spring WebFlux's equivalent class, the ModelAttributeMethodArgumentResolver, does not include these same extension methods. I am leveraging these extension methods, specifically the bindRequestParameters method, to provide valuable enhancements to my application. I would like to provide these same enhancements to the WebFlux portion of my application and am unable to do so at this time. I would like to update the WebFlux ModelAttributeMethodArgumentResolver to add the bindRequestParameters method. Modifications ------------- I created a new method called bindRequestParameters and encapsulated the WebExchangeDataBinder bind call inside of it. This method is marked as protected as it should only be used by children of this class. This change mirrors the behavior in the equivalent Spring MVC class (ModelAttributeMethodProcessor). Result ------ The WebFlux ModelAttributeMethodArgumentResolver can now accept alternative data binding implementations mirroring the Web MVC behavior.
1 parent bff1a19 commit 21887ad

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public Mono<Object> resolveArgument(
122122

123123
return valueMono.flatMap(value -> {
124124
WebExchangeDataBinder binder = context.createDataBinder(exchange, value, name);
125-
return binder.bind(exchange)
125+
return bindRequestParameters(binder, exchange)
126126
.doOnError(bindingResultMono::onError)
127127
.doOnSuccess(aVoid -> {
128128
validateIfApplicable(binder, parameter);
@@ -147,6 +147,15 @@ public Mono<Object> resolveArgument(
147147
});
148148
}
149149

150+
/**
151+
* Extension point to bind the request to the target object.
152+
* @param binder the data binder instance to use for the binding
153+
* @param exchange the current request
154+
*/
155+
protected Mono<Void> bindRequestParameters(WebExchangeDataBinder binder, ServerWebExchange exchange) {
156+
return binder.bind(exchange);
157+
}
158+
150159
private Mono<?> prepareAttributeMono(String attributeName, ResolvableType attributeType,
151160
BindingContext context, ServerWebExchange exchange) {
152161

0 commit comments

Comments
 (0)