@NotBlank(message = "userCategory is missing")
@Pattern(regexp = "Single|Married", message = "userCategory is invalid")
private String userCategory;
Currently when validation happens, it gives me two error messages when I provide a whitespaces/blank value for userCategory.
"errors": [
{
"message": "userCategory is missing"
},
{
"message": "userCategory is invalid"
}
]
I want to throw a missing value if it's whitespace/blank and don't want the invalid error in case of empty value or whitespace. I want to say userCategory is invalid only when there is something typed invalid like abddd instead of Single or Married, something other than whitespaces/empty value with a invalid value.
I'm expecting an error message something like the below when userCategory is empty or when whitespace is typed.
"errors": [
{
"message": "userCategory is missing"
}]