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/ValidationAdapter class.

Example:

invalid input: '{@code

 @ConstraintAdapter(SomeAnnotation.class)
 public final class CustomAnnotationAdapter extends AbstractConstraintAdapter<Object> {

   String value;

   public CustomAnnotationAdapter(AdapterCreateRequest req) {
      //create a message object for error interpolation and set groups
      super(req);

      //use the attributes to extract the annotation values
      value = (String) req.attribute("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