Annotation Interface Implementation.Validator

Enclosing class:
Implementation

@Target(TYPE) @Retention(RUNTIME) @Scope public static @interface Implementation.Validator

A class annotated with Implementation.Validator will be automatically searched for and instantiated as a Validator by guice.

Example

@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
@Constraint(String.class)
public @interface MaxString {
    int value();
    String message() default "The given String is too long";
}

@Validator(annotation = MaxString.class)
public class MaxStringLengthValidator implements Validator {

    @Override
   public boolean apply(Object argument, Object annotation, InvocationContext<? context) {
        MaxString maxString = (MaxString) annotation;
        return String.valueOf(argument).length() < maxString.value();
    }
}
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    @NotNull Class<? extends Annotation>
    Gets the annotation the Validator should be mapped to.
  • Element Details

    • annotation

      @NotNull @NotNull Class<? extends Annotation> annotation
      Gets the annotation the Validator should be mapped to.
      Returns:
      the annotation the Validator should be mapped to