BeanUtils.copyproperties Date property copying issue?

Ruchira Gayan Ranaweera picture Ruchira Gayan Ranaweera · May 16, 2013 · Viewed 7.9k times · Source

I am using commons-beanutils 1.8.3 and and Date properties as java.util.Date.

When i am trying to copy Source to destination it's unable to copy date properties.

Following shows my previous issue but no one give the correct answer for me.

as a example my date value in source bean is Wed May 15 15:46:04 IST 2013, but BeanUtils unable to copy this to destination...

BeanUtills Date conversion Issue

Answer

Ruchira Gayan Ranaweera picture Ruchira Gayan Ranaweera · Jun 29, 2013

This is the way I was able to solve the issue.

    public static void copyProperties(Object src, Object dest) throws IllegalAccessException,
        InvocationTargetException, NoSuchMethodException {

    java.util.Date defaultValue = null;
    Converter converter = new DateConverter(defaultValue);
    BeanUtilsBean beanUtilsBean = BeanUtilsBean.getInstance();
    beanUtilsBean.getConvertUtils().register(converter, java.util.Date.class);
    BeanUtils.copyProperties(dest, src);


}