0

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.

  1. get Class instance via Class.forName()

  2. BeanInfo info = Introspector.getBeanInfo(Class) - Here, I can see 'org.owls.anno.vo.Target'.

  3. get elements via for syntax.

    for(PropertyDescriptor pd : info.getPropertyDescriptors()){ log.info(pd.getName()); log.info(pd.getDisplayName()); log.info(pd.getPropertyType()); }

  4. 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

Juneyoung Oh
  • 7,318
  • 16
  • 73
  • 121

1 Answers1

1

Your class is not a bean: there is no accessor (getter and/or setter)...except getClass()!

C.Champagne
  • 5,381
  • 2
  • 23
  • 35
  • So you mean if my Class is not a bean, then I can not get information of class via BeanInfo interface? – Juneyoung Oh Dec 03 '13 at 11:12
  • @JuneyoungOh Well, as far as I understand, you need getters (and setters). It is not based on private instance variables, which is quite logic, I think : you access them by the accessors, never directly. – C.Champagne Dec 03 '13 at 12:36