BeanUtils.copyProperties(bean, formBean) works fine. But I have a form bean with a String array and I want to copy this too into the java bean; but I get an exception when doing this as: java.lang.IllegalArgumentException: argument type mismatch Is copyProperties() not valid for arrays?? Then what is the other way out to copy form bean values into the java bean??
[ May 21, 2004: Message edited by: Nicolas Flammel ] [ May 21, 2004: Message edited by: Nicolas Flammel ]
BeanUtils.copyProperties() does work with String arrays (I just double checked by running some test code). It's possible that there is some error in your code. The first thing to check is that you are positive it is trying to copy a String attribute in one form or bean to an attribute in another form or bean that is also a String. Are you positive that the exception is occuring because of the String? Maybe you could post some of the code here and we can take a look at it, such as the definitions of the two objects involved, and the code being used to copy them.
Joined: May 05, 2004
The array in my form bean is of type String which is being populated from the form parameters during submission(Struts)(obviously) and the one in the bean is of type Integer(as I need the same in this type). But BeanUtils.copyProperties() does auto conversion to the required types right???
Joined: Nov 09, 2000
I'm pretty sure copyProperties() does attempt to do type conversion. I probably need to study the BeanUtils source to figure out why this doesn't work. I know that the ConvertUtils class should convert a String to an Integer. I also know that using using setProperty() will correctly perform the conversion from String to Integer, although copyPropery() (which is called internally by copyProperties()) does not seem to handle this conversion correctly from String to Integer, although it will handle it from String to Integer. Interesting.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com