BeanUtils: Can convert String to Object types? (Integer, Boolean...)
1 posts in topic
Flat View  Flat View

Posted By:   Adrian_K
Posted On:   Friday, June 6, 2003 02:09 PM

I am getting some errors when I try to use the automatic population functionality that BeanUtils.copyProperties(... uses....

My question is If I have a Bean (1) and all its attributes are Strings (Struts ActionForm in my case) and I want to populate another Bean with same name properties but some of them are Integer, Double (not primitive types!)...

Can BeanUtils.copyProperties(..) make the population or just only works with primitives (int, double)....


Re: BeanUtils: Can convert String to Object types? (Integer, Boolean...)

Posted By:   AlessandroA_Garbagnati  
Posted On:   Saturday, June 7, 2003 01:25 AM


Well, first of all, String is not a primitive type, but is an Object.

Plus, copyProperties() does not work with primitives. It only works with Objects.

The org.apache.commons.beanutils.BeanUtils.copyProperties javadoc states:

[...] Copy property values from the origin bean to the destination bean for all cases where the property names are the same. For each property, a conversion is attempted as necessary. [...]

You are saying that you're getting an exception. Which one?

The method, as explained in the javadoc, does throw 4 different exception depending on the type of error. This helps the developer to solve the problem.

You have an exception if the caller does not have access to the property accessor method, two if the destination or origin argument is null, one if the property accessor method throws an exception (and in that case the exception does contain a method to get the target exception).

Once the problem is discovered, then it is possible to find a possible solution.

About | Sitemap | Contact