[ 
https://issues.apache.org/jira/browse/BEANUTILS-252?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12779649#action_12779649
 ] 

Maarten Van Avermaet commented on BEANUTILS-252:
------------------------------------------------

Why does the key of the map always requires a String, why not an object?

> getNestedProperty doesn't work with maps properly
> -------------------------------------------------
>
>                 Key: BEANUTILS-252
>                 URL: https://issues.apache.org/jira/browse/BEANUTILS-252
>             Project: Commons BeanUtils
>          Issue Type: Bug
>          Components: Bean / Property Utils
>    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.
-
You can reply to this email to add a comment to the issue online.

Reply via email to