Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8211054

Custom Validation Annotation not working properly using java 8 @Repeatable

XMLWordPrintable

    • x86_64
    • windows_7

      ADDITIONAL SYSTEM INFORMATION :
      Java version : 1.8.0_121

      A DESCRIPTION OF THE PROBLEM :
      Recently I added @Repeatable to my custom annotations. Once i added repeating annotaion to fields it was working fine , but fields with single annotoation is not working.

      Example:

      Following works:

      @NotNull
      @CustomValidator(type = Type.SIZE, max = 80)
      @CustomValidator(type = Type.FIELD)
      private String firstName;
      But following does not works(Since it contains only one @CustomValidator):

      @NotNull
      @CustomValidator(type = Type.EMAIL)
      private String email;
      CustomValidator.java

      @Constraint(validatedBy = CustomValidatorImpl.class)
      @Repeatable(RepeatableCustomValidator.class)
      public @interface CustomValidator {

          String message() default "";

          int min() default 1;

          int max() default Integer.MAX_VALUE;

          String format() default "dd.MM.yyyy";

          String[] values() default {};

          Type type();

          boolean optional() default false;

          Class<?>[] groups() default {};

          Class<? extends Payload>[] payload() default {};
      }
      RepeatableCustomValidator.java

      @Target({ ElementType.FIELD })
      @Retention(RetentionPolicy.RUNTIME)
      public @interface RepeatableCustomValidator {
          CustomValidator[] value();
      }


      Stack Overflow link : https://stackoverflow.com/questions/52382755/custom-validation-annotations-not-working-properly-using-java-8-repeatable

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Field with single custom validation annotations must also work.

      CUSTOMER SUBMITTED WORKAROUND :
      Added extra Custom annotation at class level .

      FREQUENCY : always


            psonal Pallavi Sonal (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: