I know how to access private fields via Class.forName() and Field[]. Now I am trying samething via BeanInfo Interface.
What I did is below.
get Class instance via Class.forName()
BeanInfo info = Introspector.getBeanInfo(Class) - Here, I can see 'org.owls.anno.vo.Target'.
get elements via for syntax.
for(PropertyDescriptor pd : info.getPropertyDescriptors()){ log.info(pd.getName()); log.info(pd.getDisplayName()); log.info(pd.getPropertyType()); }
I expected list of Field names(msg, open_msg), but it prints 'class.java.lang.Class'.
The Target Class is here
package org.owls.anno.vo;
import org.owls.anno.SimpleAnnotation;
@SimpleAnnotation("Add missing attributes")
public class Target {
private String msg;
public String open_msg;
public Target(String msg) {
super();
this.msg = msg;
}
@Override
public String toString() {
return "Target [msg=" + msg + "]";
}
};
Thanks for Answer :D
Your class is not a bean: there is no accessor (getter and/or setter)...except getClass()
!