Skip to content

@Valid Annotation Ignored for List Collections in Spring Boot 3.3.2 #42026

@dlsgur2845

Description

@dlsgur2845

Description:

I am currently using spring-boot-starter-validation:3.3.2 and have encountered an issue where the Valid annotation appears to be ignored when applied to a list collection of DTOs in a controller. This results in the expected validation not being performed on the DTOs within the list.

Additionally, I have noticed that when manually throwing a MethodArgumentNotValidException after detecting errors in BindingResult, the error count in BindingResult is reset to 0, even if there were validation errors prior to the exception being thrown.

Steps to Reproduce:

Use Valid annotation on a list collection of DTOs in a controller method.
Validate the DTOs and observe that the validation is not performed.
Manually check BindingResult for errors and throw new MethodArgumentNotValidException(null, bindingResult) if errors are present.
Notice that the BindingResult error count becomes 0 after the exception is thrown.
Expected Behavior:

The Valid annotation should validate each DTO in the list.
The error count in BindingResult should retain its value when throwing MethodArgumentNotValidException.
Environment:

version: spring-boot-starter-validation:3.3.2
Any guidance or workaround for this issue would be greatly appreciated.

Thank you for your attention to this matter.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions