I am using the Apache Commons BeanUtils for copying some properties from a Source Bean to a Destination Bean. In this, I do NOT want to set null values in my destination bean which are coming from the source bean.
Like for example:
Person sourcePerson = new Person();
sourcePerson.setHomePhone("123");
sourcePerson.setOfficePhone(null);
Person destPerson = new Person();
destPerson.setOfficePhone("456");
BeanUtils.copyProperties(destPerson, sourcePerson);
System.out.println(destPerson.getOffcePhone());
//Here destPerson officePhone gets set to null
How do I avoid this? I tried even putting the below statement:
BeanUtilsBean.getInstance().getConvertUtils().register(false, false, 0);
which doesn't seem to help.
Any way we can exclude nulls in Apache Commons BeanUtils?