Expose validateIfApplicable and isBindExceptionRequired as protected extension points in ModelAttributeMethodArgumentResolver#36697
Open
Arbaz4Sayyad wants to merge 1 commit intospring-projects:mainfrom
Conversation
…extension points in ModelAttributeMethodArgumentResolver This change aligns WebFlux with Spring MVC by making validation-related methods protected extension points, allowing subclasses to customize validation behavior. Changes: - Change validateIfApplicable from private to protected - Introduce isBindExceptionRequired as protected method - Replace private hasErrorsArgument helper with isBindExceptionRequired - Add test to verify protected methods can be overridden Fixes spring-projects#36690 Signed-off-by: Arbaz4Sayyad <arbaz4sayyad@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Expose validateIfApplicable and isBindExceptionRequired as protected extension points in ModelAttributeMethodArgumentResolver
This change aligns WebFlux with Spring MVC by making validation-related
methods protected extension points, allowing subclasses to customize
validation behavior.
Motivation:
When migrating from Spring MVC to WebFlux, a common customization pattern is to
subclass ModelAttributeMethodProcessor and override validateIfApplicable to apply
group-based or context-aware validation — for example, selecting different @validated
groups based on the HTTP method, tenant context, or feature flags. The same need
exists in WebFlux, but ModelAttributeMethodArgumentResolver does not support it.
Similarly, isBindExceptionRequired is overridden in MVC subclasses to control whether
a binding/validation failure should throw or be silently passed to a BindingResult
parameter — this decision sometimes needs to depend on runtime state, not just
parameter inspection.
Changes:
Precedent:
This follows the same pattern established in PR #24947, which made bindRequestParameters
protected in ModelAttributeMethodArgumentResolver. The class currently exposes two
protected reactive extension points (constructAttribute and bindRequestParameters).
validateIfApplicable sits at the same level in the binding lifecycle and should
follow the same convention.
Testing:
can be successfully overridden by subclasses
Behavioral Impact:
No behavioral changes - purely additive changes that enable extension points for
subclasses. Existing behavior is unaffected for any code that does not subclass
ModelAttributeMethodArgumentResolver.
Fixes #36690