How to get all fields along with value of Composite object?

lefadathe

New Member
I am facing issue to get value of all fields of a class by reflaction.I have one class which can have any number of fields, any number of classes and those classes in turn can have any number of fields, something like as below\[code\]public class A{ String string; int number; HashMap<String,String> map; B bclass;}\[/code\]Above B is again class member of class A.[*]I want to get fields of type String and their's values and if field is class[*]If field is Class again, then get fields and values , for example, map property is of type HashMap class type then I need both key and value properties which are of String type.Please see my code snippet to solve above problem\[code\]private void extractStringFields(Object object) throws IllegalAccessException { for (Field field : object.getClass().getDeclaredFields()) { field.setAccessible(true); System.out.println("filesd : "+field.getName()); Object value = http://stackoverflow.com/questions/15741946/field.get(object); if (field.getType().equals(String.class)) { System.out.println(field.getName() +"=" + value); } extractStringFields(field); }}\[/code\]But unfortunately, its not working, help me please.
 
Back
Top