4

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?

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

The requirement is such that one form has variable of type Date and other DateTime.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.