commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Niall Pemberton" <niall.pember...@gmail.com>
Subject Re: PropertyUtils.copyProperties() and inherited classes
Date Tue, 23 Sep 2008 19:56:20 GMT
On Tue, Sep 23, 2008 at 8:46 AM,  <Thomas.TH.Hamacher@partner.bmw.ch> wrote:
> Hi @all,
>
> as it seems, the PropertyUtils.copyProperties() as well as
> BeanUtils.copyProperties() only do a copy on "class-level".
> As I would like to reuse my copy-methods for an inherited
> class-structure I would like to ask if there is also a chance to do a
> "full"-object copy for inherited classes for all properties.
>
> ==========================================
> Example:
>
> public class Class1 {
>    private String attribute1;
> }
>
> public class Class2  extends Class1 {
>    private String attribute2;
> }
>
> public class Business {
>
>    public static copy(Class1 source, Class1 dest) {
>        PropertyUtils.copyProperties(source, dest)
>    }
> }
> ==========================================
>
> If I call Business.copy() with 2 instances of Class1, attribute1 is
> perfectly copied. But if I call the same method with 2 instances of
> Class2, only attribute1 is copied although I would also like to copy
> attribute2 as well. Any chance to do that?

It does do this - but looks like you have the parameters the wrong way
round, try

   PropertyUtils.copyProperties(dest, source)

> Furthermore I realized that enumerations are not copied, too. Is there a
> chance to copy the bean-instance including enumerations?

BeanUtils doesn't support JDK 1.5 features and it doesn't look very
likely it will do so since its pretty much in maintenance mode.

Niall

> Thanks for your help
>
> Thomas
>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message