You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "joel truher (JIRA)" <ji...@apache.org> on 2008/12/22 11:24:44 UTC
[jira] Commented: (BEANUTILS-328) String[ ] to scalar undesired
behavior at BeanUtilsBean causes limitations on designing custom Converters
[ https://issues.apache.org/jira/browse/BEANUTILS-328?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12658497#action_12658497 ]
joel truher commented on BEANUTILS-328:
---------------------------------------
I also noticed this today.
My issue is related but not identical: I want to convert String to byte[], but if the destination type is an (any) array, I get the array behavior.
delegating the entire src and dest to the converter, as suggested here, would solve the issue.
> 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.