commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Janne Mattila" <janne4444...@hotmail.com>
Subject BeanUtils.copyProperties and nested objects
Date Wed, 25 Aug 2004 11:40:36 GMT
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


Mime
View raw message