Java: 20 Springboot: 3.0.1
@NotBlank(message = "userId id can not be blank.")
@NotEmpty(message = "userId id can not be empty.")
@UUID
@User
private String userId;
now in request, I am not passing userId, I am getting any of the 4 validation error, but I am expecting, it should fail in the first validation(@NotBlank) itself.
I tried using GroupSequence like
@GroupSequence({Blank.class, Null.class, Empty.class, Custom.class, UserRequest.class})
@UserType
class UserRequest {
@NotEmpty(groups = Empty.class, message = "userId id can not be empty.")
@NotBlank(groups = Blank.class, message = "userId id can not be blank.")
@NotNull(groups = Null.class, message = "userId id can not be null.")
@UUID(groups = UID.class)
@User(groups = Custom.class)
private String userId;
}
Still randomly error message is coming, it should first give Blank error message, then Null, then empty, then UUID, then custom.
This is out of Spring Boot's control. It may be possible for Hibernate to order the reported constraint violations to match the order of the annotations but I'm not sure if the compiler, class file format, and reflection APIs provide any guarantees about that ordering. Also,
jakarta.validation.Validator.validate(T, Class<?>...)
returns aSet<ConstraintViolation<T>>
which further suggests that there may be no guarantees about the order of the constraint violations.From GitHub issue section: https://github.com/spring-projects/spring-boot/issues/35927