@Email annotation not working in springboot application

105 Views Asked by At

I have a getMapping controller which accepts emailId and Set as input. I want to have a validation check for Non empty/blank values and email id validation, below is the sample code. @Email validation is not throwing any error for invalid input. Also if i pass " " @NotEmpty or @NotNull or @NotBlank is not throwing error.

Also @Pattern is not applied to all values in Set and custom error message is not displayed

@RestController
@RequestMapping("/test")
@Validated
public class TestController {
    
    @GetMapping("/test")
    public ReturnType method(@Email @RequestParam("email") String email, @Pattern(regexp = "", message ="")Set<String> values) 
    {
     //code..
    }
1

There are 1 best solutions below

0
On

When Spring Boot finds an argument annotated with @Valid, it automatically bootstraps the default JSR 380 implementation — Hibernate Validator — and validates the argument

https://www.baeldung.com/spring-boot-bean-validation#:~:text=Of%20course%2C%20the%20most%20relevant,Validator%20%E2%80%94%20and%20validates%20the%20argument.