You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Niall Pemberton (JIRA)" <ji...@apache.org> on 2008/08/19 21:51:44 UTC
[jira] Resolved: (BEANUTILS-314) BeanUtils.describe() doesn't
handle corectly array fields like String[]
[ https://issues.apache.org/jira/browse/BEANUTILS-314?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Niall Pemberton resolved BEANUTILS-314.
---------------------------------------
Resolution: Won't Fix
The describe method converts everything to a String - so the only option you have is on how it handles String[] --> String conversion. So since BeanUtils 1.8.0 you register a String array converter that does something different than just take the first value in the Map - but in order to have describe use that converter (rather than the String converter) is to register BeanUtilsBean2. The new array converter has an option "setOnlyFirstToString" - which if you set to false will return a delimited list of all the values:
BeanUtilsBean.setInstance(new BeanUtilsBean2());
ArrayConverter converter = new ArrayConverter(String[].class, new StringConverter(), 0);
converter.setOnlyFirstToString(false);
ConvertUtils.register(converter, String[].class);
If you want the actual String array, then you need to create your own BeanUtilsBean implementation with your own describe behaviour.
hth
Niall
> BeanUtils.describe() doesn't handle corectly array fields like String[]
> -----------------------------------------------------------------------
>
> Key: BEANUTILS-314
> URL: https://issues.apache.org/jira/browse/BEANUTILS-314
> Project: Commons BeanUtils
> Issue Type: Bug
> Components: Bean / Property Utils
> Affects Versions: 1.7.0, 1.8.0-BETA
> Environment: Windows XP, Java 1.6.0_10-beta-b13
> Reporter: Tomáš Procházka
>
> When bean has array field like String[] , BeanUtils.describe() doesn't add String[] to Map, but get only first array item and convert it to String. But BeanUtils.populate(b, tMap) correctly set String[] from map to bean property.
> Here is example:
> {code:title=BeanTest.java|borderStyle=solid}
> public class BeanTest {
> public static void main(String[] args) throws Exception {
> BeanTest bt = new BeanTest();
> bt.test();
> }
> private void test() throws Exception {
> Bean b = new Bean();
> b.setData(new String[]{"a", "b", "c"});
> b.setName("ahoj");
> Map map = BeanUtils.describe(b);
> System.out.println(map.get("data"));
> System.out.println(map.get("name"));
> }
> public class Bean {
> public String[] getData() {
> return data;
> }
> public void setData(String[] data) {
> this.data = data;
> }
> public String getName() {
> return name;
> }
> public void setName(String name) {
> this.name = name;
> }
> private String[] data;
> private String name;
> }
> }
> {code}
> Expected result:
> System.out.println(map.get("data"));
> must return String[] with {"a", "b", "c"}.
> This bug is in 1.70 and also in 1.8.0
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.