It is easy to combine two simple, flat java beans using introspection:
BeanInfo info = Introspector.getBeanInfo( ContactBean.class ); PropertyDescriptor pDescArr[] = info.getPropertyDescriptors(); for(PropertyDescriptor pDesc : pDescArr){ //copy properties and check for conflicts here }
However, it gets a little more complicated when properties contain nested beans or collections. Is there a smart tool somewhere that will handle deep merging of the beans complex?
Some details on how I would like to merge:
Given the beans source collection and the empty bean target, simple properties should be copied from the source to the target if there is no conflict. If there is a conflict, the field must be empty. If the property is a collection type, the beans source values ββmust be combined, excluding duplicates and copied to the target property. These rules must be applied recursively to properties that are beans themselves.
source share