/** * Get complete inherited list of Field for Class, with the exception * that ConstructorCallback fields are not inherited. * * @param clazz Class * @return Map */ private Map<String,Field> getAllFields(Class clazz) { return this.getAllFields(clazz, false); }
private Map<String,Field> getAllFields(Class clazz, boolean isParent) { Map<String,Field> fieldsMap = new HashMap<String,Field>(); Class superClazz = clazz.getSuperclass(); if(superClazz != null){ fieldsMap.putAll( getAllFields(superClazz, true) ); } for ( Field field: clazz.getDeclaredFields() ) { field.setAccessible(true); if (isParent) { // ConstructorCallbacks are not inherited if (!field.getType().equals( ConstructorCallback.class ) ) { fieldsMap.put( field.getName(), field ); } } else { fieldsMap.put( field.getName(), field ); } } return fieldsMap; } }
Collection<Field> fields = getAllFields(blueprint.getClass()).values(); for (Field field : fields) {