commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Aaron Bruegl <abru...@nighthawkrad.net>
Subject [beanutils] populate argument type mismatch with Map
Date Thu, 21 Jun 2007 18:23:48 GMT
I am having a problem now using a Map with BeanUtils.populate. Below is 
the class 'Example' and it the error I get when running it with 
BeanUtils 1.7.0 on Java 6 update 1. I notice when debugging the code the 
'value' to be invoked for the 'setMap' method is a String with value of 
"{}"...which would explain the argument type mismatch, so is this a bug 
in BeanUtils?? I'm not sure what is going on because this just started 
being a problem for me today.

public class Example {
    public Example() {
    }
   
    private Map map = new HashMap();

    public Map getMap() {
        return map;
    }

    public void setMap(Map map) {
        this.map = map;
    }
   
    public static void main(String[] args) throws Exception {
        Example d = new Example();
       
        Map m = BeanUtils.describe(d);
       
        System.out.println(m);
       
        Example rd = (Example) 
Class.forName(Example.class.getCanonicalName()).newInstance();
        BeanUtils.populate(rd, m);
    }
}

java.lang.IllegalArgumentException: Cannot invoke 
net.nighthawk.ifd.ads.Example.setMap - argument type mismatch
        at 
org.apache.commons.beanutils.PropertyUtilsBean.invokeMethod(PropertyUtilsBean.java:1778)
        at 
org.apache.commons.beanutils.PropertyUtilsBean.setSimpleProperty(PropertyUtilsBean.java:1759)
        at 
org.apache.commons.beanutils.PropertyUtilsBean.setNestedProperty(PropertyUtilsBean.java:1648)
        at 
org.apache.commons.beanutils.PropertyUtilsBean.setProperty(PropertyUtilsBean.java:1677)
        at 
org.apache.commons.beanutils.BeanUtilsBean.setProperty(BeanUtilsBean.java:1022)
        at 
org.apache.commons.beanutils.BeanUtilsBean.populate(BeanUtilsBean.java:811)
        at 
org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:298)
        at net.nighthawk.ifd.ads.Example.main(Example.java:23)

-- 
Aaron Bruegl


---------------------------------------------------------------------
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