Skip to content

Support way to extract ConstraintViolation from HandlerMethodValidationException #33025

Closed
@kiwonseo

Description

@kiwonseo

Affects: 6.1.x or higher


I have been migrating from AOP method validation via @Validated to Spring MVC built-in method validation, added in 6.1, for queryString variable with @Constraint annotations on my controller. I have noticed that there is no simple way to extract the cause of newly thrown HandlerMethodValidationException when replacing old handler method for ConstraintViolationException.

Despite the fact that document describes HandlerMethodValidationException is "very similar" to the good old
MethodArgumentNotValidException, it lacks of the way to extract the source, ConstraintViolation while with MethodArgumentNotValidException from validating @RequestBody, you could get simply get it through ObjectError or FieldError in the exception.

HandlerMethodValidationException from validating queryString only contains DefaultMessageSourceResolvable. I think if it contains some kind of "ViolationParameterError" or something just like MethodArgumentNotValidException, it would be great to have unifying handler method for any validation exceptions from controller layer.

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions