BeanCopy the annotated bean mapper
BeanCopy ia a bean mapper that works annotation based.
To copy fields of the source and target that are different just use @Copy.
To copy fields of the source and target that are the same dont annotate them.
To prevent copying a field just use the @IgnoreCopy annotation.
Example code:
Fields with different name:
@Copy(copyTo = "testString2")
private String testString;
Fields with the same name:
private String testString;
Fields that should not be copied:
@IgnoreCopy
private String testString;
How to copy from one bean to the other:
In this case the testBean has the value and the emptyTestBean is the one where it is copied to.
TestBean testBean = new TestBean();
EmptyTestBean emptyTestBean = new EmptyTestBean();
BeanCopier beanBeanCopier = new BeanCopier();
beanBeanCopier.beanCopy(testBean,emptyTestBean);
One of the advantages of using BeanCopy is that there is no need for setter methods. This means that you can copy from model to view and vica versa.
You can also see how it works un der the hood in my blog: http://pieterroskam.blogspot.nl/2015/12/a-bit-of-reflection.html