Which approach requires the least amount of own written code to achieve a deep copy of one bean to another? The goal is to do it in an automatic way when source and target properties are matched by name.
source main bean:
public class SourceBean {
private String beanField;
private SourceNestedBean nestedBean;
// getters and setters
}
source nested bean:
public class SourceNestedBean {
private String nestedBeanField;
// getters and setters
}
target main bean:
public class TargetBean {
private String beanField;
private TargetNestedBean nestedBean;
// getters and setters
}
target nested bean:
public class TargetNestedBean {
private String nestedBeanField;
// getters and setters
}
Using e.g. Spring BeanUtils.copyProperites() I could create a shallow copy of a SourceBean
to TargetBean
with one line of code but it will not copy nested beans. Is there any mature utility (not necessarily Spring Framework) that would allow to do the deep copy while writing as least own code as possible (pretty much same as BeanUtils.copyProperties())?