0

I have couple of annotations on a getter as below. I would like to skip all the annotations call on the getter based on a boolean in the same class. Is there any way to do it?

@MyAnnotation1(message = "{someMessage1}")
@MyAnnotation2(message = "{someMessage2}")
public Date getFromDate() {
    return fromDate;
}
Superman9999
  • 815
  • 3
  • 16
  • 30
  • 1
    annotations are read by other programs to get metadata. what prog do you want to ignore it? – RNJ Oct 02 '12 at 19:04
  • If this is an spring annotation, please specify the exact annotations you are using. There no general solution that works for all kinds of annotations. – Saintali Oct 02 '12 at 20:22

1 Answers1

0

You can define another annotation as @Ignore on that field if that annotated field is set you can simply ignore your annotation processing.

   @Ignore
   private boolean value;

You can define your own annotation as

   @Target(ElementType.FIELD)
   @Retention(RetentionPolicy.RUNTIME)
   /**
    * This Annotation should be used on boolean field to set specify whether annotation processing should be        ignored for that class
    */
   public @interface Ignore {

   }

Remember this is custom annotation so you will need to write code to handle it

PS Note: Assuming you are writing custom annotations. And there processing.

Amit Deshpande
  • 19,001
  • 4
  • 46
  • 72