I need to take all the fields and collections from Bean1 and Bean2, sometimes apply some business logic, and produce Bean3 (all beans are hibernate/domain objects of the same type with a reasonably complex graph).
Any thoughts on how to do this? Done something similar in the past?
My ideas:
- Dozer (http://dozer.sourceforge.net/)
- BeanUtils (http://commons.apache.org/beanutils/)
- Handrolled solution
- A.N.Other cool solution?
Any recommendations?
Dozer is a nice bean mapping tool. However, it won't perform any business logic, of course.
I should not be a problem to implement a business logic and to rely on Dozer for bean mapping. This is what I would do.
Neither of the tools provides business logic - also it has to be implemented somehow. Bean utils are goot to access bean properties with standard notation. You may try groovy to implement business logic with nice syntax.
来源:https://stackoverflow.com/questions/12669977/java-merge-2-beans-to-produce-a-new-one