springFramework의 BeanUtils말고 apache의 BeanUtils를 상속해서 NullAwareBeanUtils를 만들면 된다.
import org.apache.commons.beanutils.BeanUtilsBean;
public class NullAwareBeanUtilsBean extends BeanUtilsBean {
@Override
public void copyProperty(Object dest, String name, Object value) throws IllegalAccessException, InvocationTargetException {
if(value == null) return; // null 값이면 복사를 수행하지 않음
super.copyProperty(dest, name, value);
}
}
사용법:
NullAwareBeanUtilsBean nullAwareBeanUtils = new NullAwareBeanUtilsBean();
nullAwareBeanUtils.copyProperties(destObject, sourceObject);