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

String[ ] to scalar undesired behavior at BeanUtilsBean causes limitations on designing custom Converters

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • None
    • 2.0.0
    • None
    • None
    • Java 1.6, BeanUtils 1.8.

    Description

      Say you have an array entry that must be converted to a scalar property. A very very simple example could be:

      String[] dateparams = new String[]

      { "10/10/2000", "10:00" }

      ;
      map.put("date", dateparams);
      BeanUtils.populate(object, map);

      So, you have a custom converter that should receive that array and perform the appropriate conversions.

      Everything would be ok, except the fact BeanUtilsBean, when populating scalar values, ignores all array values except first, as demonstrated by the following BeanUtilsBean's code:

      // Value into scalar
      if ((value instanceof String) || (value == null))

      { newValue = getConvertUtils().convert((String) value, type); }

      else if (value instanceof String[])

      { // HERE newValue = getConvertUtils().convert(((String[]) value)[0], type); }

      else

      { newValue = convert(value, type); }

      It limitates ConvertUtils power on some complex conversion designs. In think the code should be corrected to

      newValue = getConvertUtils().convert(((String[]) value), type);

      and array logic should be delegated to the converters.

      Thanks in advance,
      Fábio.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              fabiomiranda Fábio Miranda
              Votes:
              1 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated: