title: How to use an annotation element inside a custom constraint validator
body: <p>I wrote a custom annotation in my project called CGC:</p>
  
  <pre><code>@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER })
  @Retention(RUNTIME)
  @Documented
  @Constraint(validatedBy = CGCValidator.class)
  public @interface CGC {
      String message() default "{person.cgc.error}";
  
      Class&lt;?&gt;[] groups() default {};
  
      Class&lt;? extends Payload&gt;[] payload() default {};
  
      boolean canBeNull() default false;
  
      @Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER })
      @Retention(RUNTIME)
      @Documented
      public @interface List {
          CGC[] value();
      }
  }
  </code></pre>
  
  <p>I have a validator class that uses the annotation and basically, as my first validation I wanna check if the field is null, but only If the annotation for that field has specified the "canBeNull" element as true (@CGC(canBeNull="true")). My question is: how can I access the canBeNull element inside my validator class?</p>
  
  <p>*The validator should be something like this:</p>
  
  <pre><code>public class CGCValidator implements ConstraintValidator&lt;CGC, String&gt; {
  
      @Override
      public void initialize(CGC annotation) {
      }
  
      @Override
      public boolean isValid(String cgc, ConstraintValidatorContext constraintValidatorContext) {
      if(!canBeNull() &amp;&amp; cgc == null) {
      return false;
      }
      ...
  </code></pre>