親クラスオブジェクトからすべての子クラスオブジェクトを取得し、マップに配置する方法 java spring
public static Map<String, Object> ConvertObjectToMap(Object obj, Integer number) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Class<?> pomclass = obj.getClass();
pomclass = obj.getClass();
Method[] methods = obj.getClass().getMethods();
Map<String, Object> map = new HashMap<String, Object>();
for (Method m : methods) {
if (m.getName().startsWith("get") && !m.getName().startsWith("getClass")) {
Object value = null;
value = (Object) m.invoke(obj);
if (number <= 1) {
if (value.getClass().isAnnotation()) {
map.putAll(ConvertObjectToMap(value, number++));
} else {
map.put(m.getName().substring(3), (Object) value);
}
}
}
}
return map;
}
これは正しいです ?