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.
This commit is contained in:
parent
bff1a1932f
commit
21887ad23b
|
|
@ -122,7 +122,7 @@ public class ModelAttributeMethodArgumentResolver extends HandlerMethodArgumentR
|
|||
|
||||
return valueMono.flatMap(value -> {
|
||||
WebExchangeDataBinder binder = context.createDataBinder(exchange, value, name);
|
||||
return binder.bind(exchange)
|
||||
return bindRequestParameters(binder, exchange)
|
||||
.doOnError(bindingResultMono::onError)
|
||||
.doOnSuccess(aVoid -> {
|
||||
validateIfApplicable(binder, parameter);
|
||||
|
|
@ -147,6 +147,15 @@ public class ModelAttributeMethodArgumentResolver extends HandlerMethodArgumentR
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Extension point to bind the request to the target object.
|
||||
* @param binder the data binder instance to use for the binding
|
||||
* @param exchange the current request
|
||||
*/
|
||||
protected Mono<Void> bindRequestParameters(WebExchangeDataBinder binder, ServerWebExchange exchange) {
|
||||
return binder.bind(exchange);
|
||||
}
|
||||
|
||||
private Mono<?> prepareAttributeMono(String attributeName, ResolvableType attributeType,
|
||||
BindingContext context, ServerWebExchange exchange) {
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue