This is actually a common issue when working with validation annotations in Spring Boot. The problem here is that both @NotBlank and @Size(min = 2) are getting triggered, even when you send an empty string. Here’s why:
@NotBlank checks if the string is not empty (or just whitespace). @Size(min = 2) checks the length of the string to make sure it has at least 2 characters. When you send an empty string, @NotBlank will fail first because the field is empty. But Spring’s validation process doesn’t stop there — it will still evaluate other constraints, like @Size(min = 2), and give you both error messages.
In terms of validation flow, Spring doesn’t guarantee that @NotBlank will always run first, and both annotations are usually evaluated together. So in this case, you’re seeing both errors even though you expected @NotBlank to take precedence.