title: How to get all child class object from parent class object and put in map java spring
body: <p>How to get all child class object from parent class object and put in map  java spring </p>
  
  <pre><code> public static Map&lt;String, Object&gt; ConvertObjectToMap(Object obj, Integer number) throws            IllegalAccessException, IllegalArgumentException, InvocationTargetException {
      Class&lt;?&gt; pomclass = obj.getClass();
      pomclass = obj.getClass();
      Method[] methods = obj.getClass().getMethods();
      Map&lt;String, Object&gt; map = new HashMap&lt;String, Object&gt;();
      for (Method m : methods) {
          if (m.getName().startsWith("get") &amp;&amp; !m.getName().startsWith("getClass")) {
              Object value = null;
              value = (Object) m.invoke(obj);
              if (number &lt;= 1) {
                  if (value.getClass().isAnnotation()) {
                      map.putAll(ConvertObjectToMap(value, number++));
                  } else {
                      map.put(m.getName().substring(3), (Object) value);
                  }
              }
          }
      }
      return map;
  }
  </code></pre>
  
  <p>is this correct ?</p>