You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Janne Mattila <ja...@hotmail.com> on 2004/08/25 13:40:36 UTC

BeanUtils.copyProperties and nested objects

Hi,

I want to use BeanUtils.copyProperties to copy nested objects. My example 
case is:

	public static class RecordDTO {
		private ArtistDTO artist;
		private String name;
		private int id;

		...getters & setters
	}

	public static class ArtistDTO {
		private String name;
		private String firstName;
		private int id;

               ...getters and setters
       }

+ a similar structure for objects "Artist" and "Record", that are actually 
business objects. When I try to copy a business record to recordDTO with:

...
			Record r = (Record) i.next();
			RecordDTO dto  = new RecordDTO();
			BeanUtils.copyProperties(dto, r);

I get

14:08:24,246 ERROR [Engine] ----- Root Cause -----
java.lang.IllegalArgumentException: argument type mismatch
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:324)
        at 
org.apache.commons.beanutils.PropertyUtils.setSimpleProperty(PropertyUtils.java:1789)
        at 
org.apache.commons.beanutils.BeanUtils.copyProperty(BeanUtils.java:450)
        at 
org.apache.commons.beanutils.BeanUtils.copyProperties(BeanUtils.java:264)
        at cd.action.GetMainAction.testBeanUtils(GetMainAction.java:83)

should I be able to use BeanUtils to do this kind of operation?

I _believe_ I am using version 1.6 of the beanutils jar. At least 
manifest.mf states

Manifest-Version: 1.0
Created-By: Apache Ant 1.5.1
Extension-Name: org.apache.commons.beanutils
Specification-Title: Jakarta Commons Beanutils
Specification-Vendor: Apache Software Foundation
Specification-Version: 1.6
Implementation-Title: org.apache.commons.beanutils
Implementation-Vendor: Apache Software Foundation
Implementation-Version: 1.6

_________________________________________________________________
The new MSN 8: advanced junk mail protection and 2 months FREE* 
http://join.msn.com/?page=features/junkmail


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


RE: BeanUtils.copyProperties and nested objects

Posted by Koji Sekiguchi <ko...@bluemartini.com>.
I have no idea why you got this error,
you should be able to do this kind of operation
via both:

BeanUtils.copyProperties()
PropertyUtils.copyProperties()

regards,

Koji

> -----Original Message-----
> From: Janne Mattila [mailto:janne4444_63@hotmail.com]
> Sent: Wednesday, August 25, 2004 8:41 PM
> To: commons-user@jakarta.apache.org
> Subject: BeanUtils.copyProperties and nested objects
>
>
> Hi,
>
> I want to use BeanUtils.copyProperties to copy nested objects. My example
> case is:
>
> 	public static class RecordDTO {
> 		private ArtistDTO artist;
> 		private String name;
> 		private int id;
>
> 		...getters & setters
> 	}
>
> 	public static class ArtistDTO {
> 		private String name;
> 		private String firstName;
> 		private int id;
>
>                ...getters and setters
>        }
>
> + a similar structure for objects "Artist" and "Record", that are
> actually
> business objects. When I try to copy a business record to recordDTO with:
>
> ...
> 			Record r = (Record) i.next();
> 			RecordDTO dto  = new RecordDTO();
> 			BeanUtils.copyProperties(dto, r);
>
> I get
>
> 14:08:24,246 ERROR [Engine] ----- Root Cause -----
> java.lang.IllegalArgumentException: argument type mismatch
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>         at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorIm
> pl.java:39)
>         at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAc
> cessorImpl.java:25)
>         at java.lang.reflect.Method.invoke(Method.java:324)
>         at
> org.apache.commons.beanutils.PropertyUtils.setSimpleProperty(Prope
> rtyUtils.java:1789)
>         at
> org.apache.commons.beanutils.BeanUtils.copyProperty(BeanUtils.java:450)
>         at
> org.apache.commons.beanutils.BeanUtils.copyProperties(BeanUtils.java:264)
>         at cd.action.GetMainAction.testBeanUtils(GetMainAction.java:83)
>
> should I be able to use BeanUtils to do this kind of operation?
>
> I _believe_ I am using version 1.6 of the beanutils jar. At least
> manifest.mf states
>
> Manifest-Version: 1.0
> Created-By: Apache Ant 1.5.1
> Extension-Name: org.apache.commons.beanutils
> Specification-Title: Jakarta Commons Beanutils
> Specification-Vendor: Apache Software Foundation
> Specification-Version: 1.6
> Implementation-Title: org.apache.commons.beanutils
> Implementation-Vendor: Apache Software Foundation
> Implementation-Version: 1.6
>
> _________________________________________________________________
> The new MSN 8: advanced junk mail protection and 2 months FREE*
> http://join.msn.com/?page=features/junkmail
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>


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