public static void copy(Object source, Object target) throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InvocationTargetException {
Class sourceClass = source.getClass();
Class targetClass = target.getClass();
Field[] sourceFields = sourceClass.getDeclaredFields();
Field[] targetFields = targetClass.getDeclaredFields();
for(Field sourceField : sourceFields){
String name = sourceField.getName();
Class type = sourceField.getType();
String methodName = name.substring(0, 1).toUpperCase() + name.substring(1);
Method getMethod = sourceClass.getMethod("get" + methodName);
Object value = getMethod.invoke(source);
for(Field targetField : targetFields){
String targetName = targetField.getName();
if(targetName.equals(name)){
Method setMethod = targetClass.getMethod("set" + methodName, type);
setMethod.invoke(target, value);
}
}
}
}