@SuppressWarnings("unchecked") public static <T> T getValue(Object instance, String fieldName) { try { Field field = findField(instance.getClass(), fieldName); return (T) field.get(instance); } catch (Exception e) { return null; } }
@SuppressWarnings("unchecked") private static Object tryGetValueFromCustomProperties(Class<?> type, Object value, String fieldName) { Object result = null; Field field = PropertyUtils.findField(type, ResourceState.FIELD_NAME_CUSTOM_PROPERTIES); if (field != null) { try { Map<String, Object> customProperties = (Map<String, Object>) field.get(value); result = customProperties.get(fieldName); } catch (ReflectiveOperationException e) { // Do nothing here } } return result; }