You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ni...@apache.org on 2005/11/11 05:44:09 UTC

svn commit: r332448 - in /jakarta/commons/proper/beanutils/trunk/src: java/org/apache/commons/beanutils/BeanUtilsBean.java test/org/apache/commons/beanutils/BeanUtilsTestCase.java

Author: niallp
Date: Thu Nov 10 20:43:58 2005
New Revision: 332448

URL: http://svn.apache.org/viewcvs?rev=332448&view=rev
Log:
Fix further issue in Bug 17663 - getArrayProperty does not use ConvertUtils - reported by Etienne Bernard 

Modified:
    jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/BeanUtilsBean.java
    jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/BeanUtilsTestCase.java

Modified: jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/BeanUtilsBean.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/BeanUtilsBean.java?rev=332448&r1=332447&r2=332448&view=diff
==============================================================================
--- jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/BeanUtilsBean.java (original)
+++ jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/BeanUtilsBean.java Thu Nov 10 20:43:58 2005
@@ -574,7 +574,13 @@
             return (results);
         } else {
             String results[] = new String[1];
-            results[0] = value.toString();
+            try {
+                Class type = results.getClass();
+                Converter converter = getConvertUtils().lookup(type);
+                results = (String[])converter.convert(type, value);
+            } catch (Exception e) {
+                results[0] = value.toString();
+            }
             return (results);
         }
 

Modified: jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/BeanUtilsTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/BeanUtilsTestCase.java?rev=332448&r1=332447&r2=332448&view=diff
==============================================================================
--- jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/BeanUtilsTestCase.java (original)
+++ jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/BeanUtilsTestCase.java Thu Nov 10 20:43:58 2005
@@ -1,5 +1,5 @@
 /*
- * Copyright 2001-2004 The Apache Software Foundation.
+ * Copyright 2001-2005 The Apache Software Foundation.
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -406,6 +406,27 @@
 
             assertTrue("String array length = " + iarr.length,
                     (iarr.length == arr.length));
+
+
+            // Test property which isn't array or collection
+            arr = BeanUtils.getArrayProperty(bean, "shortProperty");
+            String shortAsString = "" + bean.getShortProperty();
+            assertEquals("Short List Test lth", 1, arr.length);
+            assertEquals("Short Test value", shortAsString, arr[0]);
+
+
+            // Test comma delimited list
+            String value1 = "ABC";
+            String value2 = "DEF";
+            String value3 = "GHK";
+            String delimitedList = value1 + "," + value2 + "," + value3;
+            bean.setStringProperty(delimitedList);
+            arr = BeanUtils.getArrayProperty(bean, "stringProperty");
+            assertEquals("Delimited List Test lth", 3, arr.length);
+            assertEquals("Delimited List Test value1", value1, arr[0]);
+            assertEquals("Delimited List Test value2", value2, arr[1]);
+            assertEquals("Delimited List Test value3", value3, arr[2]);
+
         } catch (IllegalAccessException e) {
             fail("IllegalAccessException");
         } catch (InvocationTargetException e) {



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org