Annotation Interface ConstraintAdapter


@Target(TYPE) public @interface ConstraintAdapter
Marks a type as a Constraint Adapter to be registered automatically.

A custom adapter registered using this annotation must have a public constructor accepting a ValidationContext instance, and must extend the AbstractConstraintAdapter class.

Example:

invalid input: '{@code
 @ConstraintAdapter(SomeAnnotation.class)
 public final class CustomAnnotationAdapter extends AbstractConstraintAdapter<Object> {

   String value;

   public CustomAnnotationAdapter(ValidationContext ctx, Set<Class<?>> groups, Map<String, Object> attributes) {
     //create a message object for error interpolation and set groups
      super(ctx.message(attributes), groups);

      //use the attributes to extract the annotation values
      value = (String) attributes.get("value");
   }


 	 @Override
   public boolean isValid(Object value) {

     var isValid = ...custom validation based on the attributes;

     return isValid;
 }

 }</pre>'
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    Class<? extends Annotation>
    The Annotation this validator targets
  • Element Details

    • value

      Class<? extends Annotation> value
      The Annotation this validator targets