How can I get the value of the annotation using Java Reflection
?
This is the annotated method:
@JsonView( { View.class } )
public Element getElement()
{
return element;
}
Assuming that your method is declared in class MyClass
, do the following:
MyClass.class.getMethod("getElement").getAnnotation(JsonView.class).value()
Here the some way to get annotation,
Class<?> cls = Class.forName(name);
cls.getDeclaredAnnotations(); // get all annotation
(cls.getDeclaredMethods()[0]).getAnnotations(); //get annotation of a method
Annotation ety = cls.getAnnotation(Annotation.class); // get annotation of particular annotation class
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With