Java beans merge tools

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.

+3
source share
2 answers

Dozer or Smooks . Dozer is a winner if you just want a bean merge. If you are looking for other usecases like csv to pojo etc. then take a look at Smooks.

+2
source

You can use apache common beanutils . There is no built-in method to accomplish what you are trying to do, but you can use helper methods to achieve the same

0
source

Source: https://habr.com/ru/post/1396192/


All Articles