public static Object get(Object object, String propertyName) {
if (object != null && propertyName != null) {
return get(object, object.getClass(), propertyName);
}
return null;
}
public static Object get(Object object,Class clazz, String propertyName) {
if (object != null&&clazz!=null && propertyName != null&&clazz!=Object.class) {
try {
Field field = clazz.getDeclaredField(propertyName);
field.setAccessible(true);
return field.get(object);
} catch (NoSuchFieldException e) {
return get(object, clazz.getSuperclass(), propertyName);
}catch (Exception e) {
return null;
}
}
return null;
}
public static boolean set(Object object, String propertyName,Object propertyValue) {
if (object != null && propertyName != null) {
return set(object, object.getClass(), propertyName,propertyValue);
}
return false;
}
public static boolean set(Object object,Class clazz, String propertyName,Object propertyValue) {
if (object != null&&clazz!=null && propertyName != null&&clazz!=Object.class) {
try {
Field field = clazz.getDeclaredField(propertyName);
field.setAccessible(true);
field.set(object, propertyValue);
return true;
} catch (NoSuchFieldException e) {
return set(object, clazz.getSuperclass(), propertyName,propertyValue);
}catch (Exception e) {
return false;
}
}
return false;
}