I have a RESTful service which receives POST
request with UUID
values and writes them in DB. So the problem is to validate if UUID
is valid or not. For this purpose I implemented custom annotation:
@Constraint(validatedBy = {})
@Target({ElementType.FIELD})
@Retention(RUNTIME)
@Pattern(regexp = "[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[34][0-9a-fA-F]{3}-[89ab][0-9a-fA-F]{3}-[0-9a-fA-F]{12}")
public @interface validUuid {
String message() default "{invalid.uuid}";
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};
}
But for some reason it doesn't work, even if I pass valid UUID
I constantly get an exception:
javax.validation.UnexpectedTypeException: HV000030: No validator could be found for constraint 'javax.validation.constraints.Pattern' validating type 'java.util.UUID'
Are there any options to validate UUID
properly?