commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Fábio Miranda (JIRA) <j...@apache.org>
Subject [jira] Created: (BEANUTILS-328) String[ ] to scalar undesired behavior at BeanUtilsBean causes limitations on designing custom Converters
Date Mon, 20 Oct 2008 14:31:44 GMT
String[ ] to scalar undesired behavior at BeanUtilsBean causes limitations on designing custom
Converters
---------------------------------------------------------------------------------------------------------

                 Key: BEANUTILS-328
                 URL: https://issues.apache.org/jira/browse/BEANUTILS-328
             Project: Commons BeanUtils
          Issue Type: Bug
         Environment: Java 1.6, BeanUtils 1.8.
            Reporter: Fábio Miranda
            Priority: Minor


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.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message