I have a simple Java POJO that I would copy properties to another instance of same POJO class.
I know I can do that with BeanUtils.copyProperties() but I would like
You can achieve it using Java Reflection API.
public static void copy(T target, T source) throws Exception {
Class> clazz = source.getClass();
for (Field field : clazz.getDeclaredFields()) {
if (Modifier.isPrivate(field.getModifiers()))
field.setAccessible(true);
Object value = field.get(source);
field.set(target, value);
}
}