[ http://issues.apache.org/jira/browse/BEANUTILS-252?page=all ]
Niall Pemberton updated BEANUTILS-252: -------------------------------------- Component/s: Utils (Bean, Property, Method) > getNestedProperty doesn't work with maps properly > ------------------------------------------------- > > Key: BEANUTILS-252 > URL: http://issues.apache.org/jira/browse/BEANUTILS-252 > Project: Commons BeanUtils > Issue Type: Bug > Components: Utils (Bean, Property, Method) > Affects Versions: 1.7.0 > Environment: Any > Reporter: Masker71 > > Hello, > Here is an example of PropertyUtils.getProperty use: > HashMap myMap = new HashMap(); > myMap.put("key","value"); > Request: > System.out.println(PropertyUtils.getProperty(myMap, "(key)")); > Result: > null > Workaround: > HashMap myMap = new HashMap(); > myMap.put("(key)","value"); > Request: > System.out.println(PropertyUtils.getProperty(myMap, "(key)")); > Result: > value > The reason of this behaviour is that in the implementation of > PropertyUtilsBean.getNestedProperty function. > Currently it doesn't extract 'key' from brackets. variable name is equal to > "(key)" when this method is invoked > and it is used to extract value from the map: > indexOfINDEXED_DELIM = name.indexOf(PropertyUtils.INDEXED_DELIM); > indexOfMAPPED_DELIM = name.indexOf(PropertyUtils.MAPPED_DELIM); > if (bean instanceof Map) { > bean = ((Map) bean).get(name); > } else if (indexOfMAPPED_DELIM >= 0) { > bean = getMappedProperty(bean, name); > } else if (indexOfINDEXED_DELIM >= 0) { > bean = getIndexedProperty(bean, name); > } else { > bean = getSimpleProperty(bean, name); > } > For the bean methods which returs maps key extraction is performed, why it > isn't done for the Map? Cannot I use any string as a key in the map, why > should I use keys enveloped in brackets? I think what is mentioned to do is > that: > indexOfINDEXED_DELIM = name.indexOf(PropertyUtils.INDEXED_DELIM); > indexOfMAPPED_DELIM = name.indexOf(PropertyUtils.MAPPED_DELIM); > indexOfMAPPED_DELIM2 = name.indexOf(PropertyUtils.MAPPED_DELIM2); > if (bean instanceof Map) { > if (indexOfMAPPED_DELIM >= 0 && indexOfMAPPED_DELIM2>=0) > name = name.substring(indexOfMAPPED_DELIM+1, > indexOfMAPPED_DELIM2); > bean = ((Map) bean).get(name); > } > Hope description was clear enough and you will approve it as a bug. > Thank you -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]