Issue
I am using spring boot.
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
For same property I am giving two annotations one is for null check another is for empty check.
@NotNull(message = "{email.notnull}")
@NotEmpty(message = "{email.notempty}")
private String email;
I am loading the error messages from properties file.
When I give email as empty then I am getting the error message from email.notempty
only, but when I give email as null then email.notnull
and email.notempty
these two error messages are displaying, May I Know what is the mistake that I have done.
I should be able to see only null error when I have given null.
Solution
As the @NotEmpty
documentation states
The annotated element must not be null nor empty.
It has an implicit not null requirement so you can drop @NotNull
.
See also Difference Between @NotNull, @NotEmpty, and @NotBlank Constraints in Bean Validation
Answered By - hisener