Source:
<code>private <T extends Dto> HashMap<String, Object> buildRequestData(Class<T> classOfT, T entity) { HashMap<String, Object> result = new HashMap<>(); ArrayList<String> readOnlyProperties = entity.getReadOnlyProperties(); <START> Class c = entity.getClass(); <END> List<Field> fields = new ArrayList<>(); fields.addAll(Arrays.asList(c.getDeclaredFields())); while (c.getSuperclass() != null) { fields.addAll(Arrays.asList(c.getSuperclass().getDeclaredFields())); c = c.getSuperclass(); } String fieldName; for (Field f : fields) { f.setAccessible(true); boolean isList = false; for (Class<?> i : f.getType().getInterfaces()) { if (i.getName().equals("java.util.List")) { isList = true; break; } } fieldName = fromCamelCase(f.getName()); boolean isReadOnly = false; for (String s : readOnlyProperties) { if (s.equals(fieldName)) { isReadOnly = true; break; } } if (isReadOnly) continue; if (canReadSubRequestData(classOfT, fieldName)) { HashMap<String, Object> subRequestData = new HashMap<>(); try { Method m = RestTool.class.getDeclaredMethod("buildRequestData", Class.class, Dto.class); subRequestData = (HashMap<String, Object>) m.invoke(this, f.getType(), f.get(entity)); } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { if (this.debugMode) logger.error("EXCEPTION: {}", Arrays.toString(ex.getStackTrace())); } for (Entry<String, Object> e : subRequestData.entrySet()) { result.put(e.getKey(), e.getValue()); } } else { try { if (!isList) { result.put(fieldName, f.get(entity)); } else { result.put(fieldName, ((List) f.get(entity)).toArray()); } } catch (IllegalArgumentException | IllegalAccessException ex) { continue; } } } return result; }</code><technical_language>Refactor this part a method, returns recursively fields of a class. I is line :631</technical_language>

Target:
private <T extends Dto> HashMap<String, Object> buildRequestData(Class<T> classOfT, T entity) { HashMap<String, Object> result = new HashMap<>(); ArrayList<String> readOnlyProperties = entity.getReadOnlyProperties(); List<Field> fields = getAllFields(entity.getClass()); String fieldName; for (Field f : fields) { f.setAccessible(true); boolean isList = false; for (Class<?> i : f.getType().getInterfaces()) { if (i.getName().equals("java.util.List")) { isList = true; break; } } fieldName = fromCamelCase(f.getName()); boolean isReadOnly = false; for (String s : readOnlyProperties) { if (s.equals(fieldName)) { isReadOnly = true; break; } } if (isReadOnly) continue; if (canReadSubRequestData(classOfT, fieldName)) { HashMap<String, Object> subRequestData = new HashMap<>(); try { Method m = RestTool.class.getDeclaredMethod("buildRequestData", Class.class, Dto.class); subRequestData = (HashMap<String, Object>) m.invoke(this, f.getType(), f.get(entity)); } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { if (this.debugMode) logger.error("EXCEPTION: {}", Arrays.toString(ex.getStackTrace())); } for (Entry<String, Object> e : subRequestData.entrySet()) { result.put(e.getKey(), e.getValue()); } } else { try { if (!isList) { result.put(fieldName, f.get(entity)); } else { result.put(fieldName, ((List) f.get(entity)).toArray()); } } catch (IllegalArgumentException | IllegalAccessException ex) { continue; } } } return result; }