Hi all,

I have employee class which I have 100 variables with getters and setters.
now I am passing employee object to processing method. Now I want to read all values in processing method.

Should I want to use getter for all member? Is there any way to achieve this.

pls any one help me

You can use the java.beans.Introspector class to get the BeanInfo for your bean. Then use the BeanInfo to get the PropertyDescriptors. That gives you an array of all the properties, from which you can call getReadMethod() to get each of the bean's get methods. You can invoke those methods to get all the property values.

Hi JamesCherrill,

Thanks for the reply
I have tried java.beans.Introspector with following code.In that I want to get the values of testBean object. How can I get that particular objects value. Could please help me.

    TestBean testBean = new TestBean();
    testBean.setId("01");
    testBean.setName("myname01");
    TestBean testBean1 = new TestBean();
    testBean1.setId("02");
    testBean1.setName("myname02");
    BeanInfo info = Introspector.getBeanInfo(TestBean.class);
    for (PropertyDescriptor pd : info.getPropertyDescriptors()) {
        System.out.println(pd.getName());
        System.out.println(pd.getValue(pd.getName()));
        System.out.println(pd.getReadMethod());
    }

pd.getReadMethod() gives you a Method object that represents a "get" method for the Bean. You can call the Method object's invoke method to execute the "get" method it represents and return the result

Edited 2 Years Ago by JamesCherrill

Thanks for your help .
now its working with following code

pd.getReadMethod().invoke(testBean)

Edited 2 Years Ago by anand01: added code

Dear JamesCherrill,
In the above code pd.getName() gives the list of bean variables in sorted order. Do we have any option for the same order in the class.
Thanks in advance.

Edited 2 Years Ago by anand01: edit

This question has already been answered. Start a new discussion instead.