commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <>
Subject Re: copyperoperties
Date Mon, 20 Jan 2003 06:01:54 GMT

On Mon, 20 Jan 2003, usha rani wrote:

> Date: Mon, 20 Jan 2003 13:19:07 +0800
> From: usha rani <>
> Reply-To: Jakarta Commons Users List <>
> To:
> Subject: copyperoperties
> Hi
> can i use BeanUtils.copyProperties() to copy from one bean to another. where
> the origin bean is having String datatype and destination bean is having
> Integer datatype

Um, just use it?  :-)

The important rule for copyProperties() is that the property names in the
two beans must be the same.  Then, as the copying takes place, BeanUtils
will notice the two data types are not the same, and look up a Converter
that knows how to perform the needed conversion.

For example:

  public class OrigBean {
    public String getCount();
    public void setCount(String count);

  public class DestBean {
    public int getCount();
    public void setCount(int count);

and in your application:

  OrigBean orig = new OrigBean();
  DestBean dest = new DestBean();
  BeanUtils.copyProperties(dest, orig);
  ... dest.getCount() will return 123 here ...

If you want to use a data type that does not have a preregistered
converter, you'll have to create and register your own.  For more info,
see the JavaDocs for commons-beanutils, available online at:

In particular, read the "Package Description" section for the
org.apache.commons.beanutils package.

> Thanks
> usha


View raw message