Search code examples
javaspringvalidationspring-bootannotations

How to enable javax annotations when value not null and disabled when value is null?


I need to disable validation if the value of email is null and check on it if the value is not null.

@Email(message = "{invalidMail}")
private String email;

Solution

  • I found the answer and it's that almost all java validation annotations accepts null so if my value is null it's going to accept it otherwise it will check.