Comments (7)
Example added.
from spring-framework.
Thanks for the report. It would help a lot if you could provide snippets, or a small sample to experiment with.
from spring-framework.
Thanks for the report. It would help a lot if you could provide snippets, or a small sample to experiment with.
I will post one later today.
Note that it will simply be a GetMapping
method with 2 arguments that have constraints and a method level cross-parameter constraint whose isValid
method always returns false.
from spring-framework.
Workaround added.
from spring-framework.
Thanks for the sample.
For cross-parameter validation, the property path has the method node and then a cross-parameter node, but no other useful info on which parameters were validated or what the argument values were. Is that because the ConstraintValidator
implementation is empty and just returns false? In other words is the validator able to and expected to update the context in a way that would expose more information in the resulting ConstraintViolation
?
At any rate, a cross-parameter violation does not fit into the current model where a MethodValidationResult
holds value results (violations of parameter constraints) or bean results (violations of nested object field constraints) both of which aggregate violations for a specific method parameter.
We could create a CrossParameterValidationResult
that holds basic MessageSourceResolvable
's prepared from the annotation name and the target class/method name, but I'm not sure if we can get anything more useful than that.
from spring-framework.
I 100% agree that the current model doesn't fit.
The challenge in my mind is, at the end of the day, we need a single exception type that holds all method argument ConstraintViolations
.
This exception type should contain violations of cross-parameter constraints and violations of individual arguments annotated with @Constraints
or annotated with @Valid
.
This would provide a complete solution for handling pre-method execution ConstraintViolations
.
The MethodValidationResult
and MethodValidationException
names imply this functionality but currently require a lot of finagling to achieve it (ConstraintViolation
manipulation in the case of cross-parameter constraints and the requirement to have additional @Constraints
on the method for '@Valid` to be evaluated ).
Thanks for the sample.
For cross-parameter validation, the property path has the method node and then a cross-parameter node, but no other useful info on which parameters were validated or what the argument values were. Is that because the
ConstraintValidator
implementation is empty and just returns false? In other words, is the validator able to and expected to update the context in a way that would expose more information in the resultingConstraintViolation
?At any rate, a cross-parameter violation does not fit into the current model where a
MethodValidationResult
holds value results (violations of parameter constraints) or bean results (violations of nested object field constraints) both of which aggregate violations for a specific method parameter.We could create a
CrossParameterValidationResult
that holds basicMessageSourceResolvable
's prepared from the annotation name and the target class/method name, but I'm not sure if we can get anything more useful than that.
from spring-framework.
the requirement to have additional
@Constraints
on the method for '@Valid` to be evaluated
I'm not sure what you mean. @Valid
does not need anything else to trigger validation. It is true that if there are no @Constraint
s at all on method parameter, then it is validated on its own, raising MethodArgumentNotValidException
, which is designed to be very similar to MethodValidationException
and one can be adapted to the other. This is covered in the docs.
You do raise a point that with method level @Constraint
s, currently we assume they are for the return value, but it may be for cross-parameter validation. If this is what you are pointing out, then yes, we do need to update that.
ConstraintViolation manipulation in the case of cross-parameter constraints
For the rest, I proposed above a CrossParameterValidationResult
held in MethodValidationResult
in addition to ParameterValidationResult
s. However, I don't see a way to tell which specific parameters were involved, which means we can't aggregate cross-parameter violations in any way. So we might just expose a list of MessageSourceResolvable
s from MethodValidationResult
that represent cross-param violations.
from spring-framework.
Related Issues (20)
- Efficient handling of conditional HTTP requests HOT 1
- `BindingReflectionHintsRegistrar` do not take into account the boxed type `Boolean`
- Resolve new package cycle between `web.servlet.handler` and `web.servlet.function`
- Harmonize Reactor Netty client class names
- New threads added to thread pool inherit active database transaction in tests
- spring native not support method handler with kotlin default value
- Encapsulate ETag comparison logic
- SimpleEvaluationContext should disable array allocation HOT 1
- Wrong warning logged for multiple `@RequestMapping` annotations HOT 8
- Provide a public mechanism for detecting if AOT processing is in progress
- WebTestClient leaks when ParameterizedTypeReference is used
- Overriding rsocket decoders
- Document non-default candidate beans and Java-based configuration of non-autowire candidate beans
- Feature Request: Scoped Bean Injection Control by Bean Creators HOT 2
- Upgrade to JUnit 5.11
- MultipartFile transferTo() copies the previously uploaded file as a new file HOT 5
- RestClient doesn't open a scope for the processing of the request HOT 3
- Build documentation branches only for 6.1 and later
- Injecting one qualified bean disrupts the ability to inject another qualified bean by subtype HOT 1
- Request to provide Primary Exception Handler to resolve `Ambiguous @ExceptionHandler method mapped for [Exception]`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spring-framework.