spring-boot
spring-boot copied to clipboard
@Valid Annotation Ignored for List Collections in Spring Boot 3.3.2
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.
Could you please provide a sample application that reproduces the problem.
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.