You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Oliver Heger (JIRA)" <ji...@apache.org> on 2013/11/21 22:21:35 UTC

[jira] [Commented] (BEANUTILS-453) there was no why, to get value from the map, which have the key type of enum

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

Oliver Heger commented on BEANUTILS-453:
----------------------------------------

Thanks for your contribution. However, I am reluctant for adding this feature.

First, the documentation clearly states that mapped properties use a String as key. From section 2.1 of the user guide:
{quote}
Mapped - As an extension to standard JavaBeans APIs, the BeanUtils package considers any property whose underlying value is a java.util.Map to be "mapped". You can set and retrieve individual values via a String-valued key.
{quote}

This is also in-line with the signature of the {{getMappedProperty()}} and {{setMappedProperty()}} methods which expect the key to be a string and not an arbitrary object.

You do not take the {{setMappedProperty()}} method into account. It would be possible to use it to write values into the enum-keyed map. But because the method does not know the actual type of the keys in the map it would simply insert String keys. This might later cause ClassCastExceptions. So the get and set methods for mapped properties are no longer symmetric.

What also worries me is that your proposed fix can have an impact on performance in certain constellations. You check whether the passed in key is found in the map. If not, you iterate over all keys contained in the map. This is now always done, no matter whether the map's keys are strings or anything else. It might be an expected case that a key cannot be resolved, but with the proposed change then the whole map has to be scanned. For large maps this may be an issue.

> there was no why, to get value from the map, which have the key type of enum
> ----------------------------------------------------------------------------
>
>                 Key: BEANUTILS-453
>                 URL: https://issues.apache.org/jira/browse/BEANUTILS-453
>             Project: Commons BeanUtils
>          Issue Type: Improvement
>          Components: Bean / Property Utils
>    Affects Versions: 1.8.3, 1.8.4, 1.9.0
>            Reporter: vakhtang koroghlishvili
>            Priority: Critical
>              Labels: features, patch, test
>         Attachments: MapWithEnumKey_withTestCase.patch
>
>
> There was no why, to get value from the map, which have key type of Enum. So I solve the problem and I will upload my patch (with Junit test cases).



--
This message was sent by Atlassian JIRA
(v6.1#6144)