Module io.avaje.validation
Package io.avaje.validation.adapter
Annotation Interface ConstraintValidator
Marks a type as a Constraint Validator to be registered automatically.
A custom adapter registered using this annotation must have a public constructor accepting a ValidationContext instance, and must directly implement the ValidationAdapter Interface.
Example:
invalid input: '{@code
@ConstraintValidator(SomeAnnotation.class)
public final class CustomAnnotationAdapter implements ValidationAdapter<Object> {
private final Message message;
public CustomAnnotationAdapter(ValidationContext ctx, Set<Class<?>> groups, Map<String, Object> attributes) {
//create a message object for error interpolation
message = ctx.message("{message.property}");
//use the attributes to extract the annotation values
}
@Override
public boolean validate(Object value, ValidationRequest req, String propertyName) {
var isValid = ...custom validation based on the attributes;
if (!isValid) {
req.addViolation(message, propertyName);
return false;
}
return true;
}
}</pre>'-
Required Element Summary
Required ElementsModifier and TypeRequired ElementDescriptionClass<? extends Annotation>The Annotation this validator targets
-
Element Details
-
value
Class<? extends Annotation> valueThe Annotation this validator targets
-