Uploaded image for project: 'Commons BeanUtils'
  1. Commons BeanUtils
  2. BEANUTILS-376

Supporting indexed (mapped) properties of Map objects

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Reopened
    • Minor
    • Resolution: Unresolved
    • None
    • None
    • Bean / Property Utils
    • None
    • JDK1.5_22, WinXP

    Description

      So far, BeanUtils does not support indexed or mapped properties of Map object (PropertyUtilsBean.getPropertyOfMapBean(Map bean, String propertyName) )
      and throw IllegalArgumentException.

      For instance if you have Map<String, String[]> and you want to get property by calling propName[0] (or propName(0)), method isIndexed (isMapped) of DefaultResolver returns true which raises previously mentioned exception. From my point of view it seems that method gets data which needs and is possible to parse propertyName to get desired result.

      E.g. something similar to:

      if (resolver.isIndexed(propertyName)) {
         String name = resolver.getProperty(propertyName);
         int idx = Integer.valueOf(resolver.getIndex(propertyName)); // handle NumberFormat exception by your way
         return ((Object[]) bean.get(name))[idx]; // handle ArrayIndexOutOfBounds and ClassCast exception by your way
      }
      

      I was a bit surprised that I didn't find this issue in existing ones. I'm sorry if there is any which I omitted.
      Is it possible that this funcionality will be provided in any future release? Thank you

      Attachments

        1. beanutils.patch
          4 kB
          Zdeněk Obst

        Issue Links

          Activity

            People

              Unassigned Unassigned
              d1x Zdeněk Obst
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated: