Reputation: 579
I have 2 form Classes
public class Form1{
int id,
String name,
DateTime lastModified;
//setters and getters
}
public class Form2 {
int id,
String name,
Date lastModified;
//setters and getters
}
ie., one of the form has the same variable name lastModified with Date type and other one with joda DateTime type
I am trying to copy form1 values to form2
Form1 form1 = dao.getForm1();
Form2 form2 = new Form2();
BeanUtils.copyProperties(form2,form1)
But it is giving me error like
org.apache.commons.beanutils.ConversionException: DateConverter does not support default String to 'Date' conversion.
I tried the solution given in
https://stackoverflow.com/a/5757379/1370555
But it is giving me error like
org.apache.commons.beanutils.ConversionException: Error converting 'org.joda.time.DateTime' to 'Date' using pattern 'yyyy-MM-dd HH:mm:ss.0 Z'
I think it can be solved with apache ConvertUtils but i am not getting exactly how it is to be done
Can any one help me solve this?
Upvotes: 4
Views: 2348
Reputation: 6665
BeanUtils.copyProperties(form2,form1)
copies the property values of one form to another form.Since your both forms have lastModified
property with different data types and org.joda.time.DateTime
is not compatible with java.util.Date
, you are getting the exception.
You can change the property to same reference types or have a constructor which will assign the value to a matching data type of a same variable reference
Upvotes: 1