title: How to get all fields along with value of Composite object?
body: <p>I am facing issue to get value of all fields of a class by reflaction.</p>
  
  <p>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</p>
  
  <pre><code>public class A{
      String string;
      int number;
      HashMap&lt;String,String&gt; map;
      B bclass;
  }
  </code></pre>
  
  <p>Above B is again class member of class A.</p>
  
  <ol>
  <li>I want to get fields of type <strong>String</strong> and their's values and if field is class</li>
  <li>If field is <strong>Class</strong> again, then get fields and values , for example, <strong>map</strong> property is of type <strong>HashMap</strong> class type then I need both key and value properties which are of <strong>String</strong> type.</li>
  </ol>
  
  <p>Please see my code snippet to solve above problem</p>
  
  <pre><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 = field.get(object);
  
          if (field.getType().equals(String.class)) {
              System.out.println(field.getName() + "=" + value);
          }
          extractStringFields(field);
      }
  }
  </code></pre>
  
  <p>But unfortunately, its not working, help me please.  </p>