title: Making a Jersey bean validation annotation generic
body: <p>I have a Jersey Rest API like this:</p>
  
  <pre><code>@POST
  @Path("/doorder")
  @Consumes(MediaType.MULTIPART_FORM_DATA)
  @Produces("text/plain")
  public String doOrder(@BeanParam final @Valid OrderBean order) {
  
      // Some implementation here
  }
  </code></pre>
  
  <p>All my inputs are store in this bean:</p>
  
  <pre><code>@AddressAtLeastOne
  public final class OrderBean {
  
      @FormDataParam("address")
      private String address;
  
      @FormDataParam("city")
      private String city;
  
      @FormDataParam("postcode")
      private String postcode;
  
          // Other member variables
  
          // Getters and setters
  
  }
  </code></pre>
  
  <p>I added an annotation to validate the address (@AddressAtLeastOne). The address is valid if at least one of the 3 fields has a value.</p>
  
  <p>Here's the annotation definition:</p>
  
  <pre><code>@Target({ElementType.METHOD, ElementType.FIELD, ElementType.ANNOTATION_TYPE, ElementType.CONSTRUCTOR, ElementType.PARAMETER, ElementType.TYPE_USE})
  @Retention(RUNTIME)
  @Constraint(validatedBy = AddressAtLeastOneValidator.class)
  @Documented
  public @interface AddressAtLeastOne {
  
      String message() default "Address requires at least one field";
  
      Class&lt;?&gt;[] groups() default {};
  
      Class&lt;? extends Payload&gt;[] payload() default {};
  }
  </code></pre>
  
  <p>And here's the validator:</p>
  
  <pre><code>public class AddressAtLeastOneValidator implements ConstraintValidator&lt;AddressAllOrNone, OrderBean&gt; {
  
      @Override
      public boolean isValid(OrderBean demoBean, ConstraintValidatorContext constraintValidatorContext) {
  
      // Check for at least one value
      if((demoBean.getAddress() != null &amp;&amp; !demoBean.getAddress().equals("") ||
              (demoBean.getCity() != null &amp;&amp; !demoBean.getCity().equals("")) ||
              (demoBean.getPostcode() != null &amp;&amp; !demoBean.getPostcode().equals("")))) {
          return true;
      }
  
      return false;
      }
  }
  </code></pre>
  
  <p>Everything is fine! But now I want to rename the annotation @AddressAtLeastOne to @AtLeastOne and make it generic, so that I can apply it to any class. I need a mechanism where I can specify which member variables are part of the group I want to validate with @AtLeastOne. How can I do that?</p>