commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From robert burrell donkin <robertburrelldon...@blueyonder.co.uk>
Subject Re: [BeanUtils]: describe method bug with array as bean property
Date Thu, 01 May 2003 18:28:44 GMT
hi Shawn

On Friday, April 25, 2003, at 03:55 PM, Martin Rose wrote:

> I would really enjoy getting this patch in, I've had a sort of work 
> around for a bit, and hadn't
> had the time to implement/dig into what you've implemented below.
>
> The "best" way to probably get this in would be to file a bug report 
> against Beanutils, with this
> test below.
>
> http://nagoya.apache.org/bugzilla/enter_bug.cgi?product=Commons
>
> And also to come up with any unit tests that will test the new 
> functionality. And submit those as
> well...

+1

on commons components, i personally spend much more time writing unit 
tests than i do writing code. (maybe two-to-one.) so, a patch with unit 
tests will take me less time to review and that means i'm more likely to 
find time to do it. (i can't speak for anyone else but i think that they 
probably feel the same.)

> You'll probably then need to bring it up occasionally on the list, esp 
> before any realeses to make sure it gets tested/applied.

+1

we're all volunteers and we only have a limited amount of time. if you do 
file a bug report, it's a good idea to raise it on the list as well - it's 
much easier for me to ask questions and that means i'm more likely to 
devote time to reviewing the patch (rather than the 101 other things i 
could be doing).

if you haven't already, you might like to read 
http://jakarta.apache.org/commons/patches.html.

- robert

> Hope that helps, and good luck. ;)
>
> Marty
>
>
> --- hughes_shawn@jpmorgan.com wrote:
>> I've read the "Roles & Responsibilities" document and would like to
>> contribute this change.  Not sure if there's an easier way so here goes.
>> ..
>>
>> The BeanUtils.describe method does not fully describe the bean when an
>> array property exists.  It only shows the first entry of the array.
>>
>> I've made the changes to org.apache.commons.beanutils.ConvertUtils to
>> support array property description.  It works on Object and primitive
>> arrays as well as recursively on arrays of arrays.
>>
>> Here's the modified section of the
>> org.apache.commons.beanutils.ConvertUtils.convert() method:
>>
>> Old:
>>
>>         } else if (value.getClass().isArray()) {
>>             if (Array.getLength(value) < 1) {
>>                 return (null);
>>             }
>>             value = Array.get(value, 0);
>>             if (value == null) {
>>                 return ((String) null);
>>             } else {
>>                 Converter converter = (Converter)
>> converters.get(String.class);
>>                 return ((String) converter.convert(String.class, value))
>> ;
>>             }
>>         } else {
>>
>> New:
>>
>> // New constant in class
>> protected static final String arrayEntrySeparator = ", ";
>>
>>         } else if (value.getClass().isArray()) {
>>             if (Array.getLength(value) < 1) {
>>                 return (null);
>>             }
>>             StringBuffer sb = new StringBuffer();
>>              sb.append("[");
>>              int length = Array.getLength(value);
>>              for (int i=0; i<length; i++) {
>>                Object val2 = Array.get(value, i);
>>                if (val2.getClass().isArray()) {
>>                     sb.append(convert(val2) + arrayEntrySeparator);
>>                } else if (val2 == null) {
>>                     sb.append("null" + arrayEntrySeparator);
>>                  } else {
>>                      Converter converter = (Converter)
>> converters.get(String.class);
>>                      sb.append(((String) converter.convert(String.class,
>> val2)) + arrayEntrySeparator);
>>                  }
>>              }
>>              // Delete final comma and space, no more entries
>>              sb.delete(sb.length()-2,sb.length());
>>              sb.append("]");
>>             return sb.toString();
>>         } else {
>>
>> Caveats:
>>   - I followed the ArrayList.toString() output format [a1, a2] for 
>> arrays.
>> If a new JDK release changes this (doubtful but possible) this code will
>> require modification for consistency purposes.
>>   - The result could get large if the internal arrays are large.
>>
>> Shawn.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>>
>
>
> __________________________________________________
> Do you Yahoo!?
> The New Yahoo! Search - Faster. Easier. Bingo
> http://search.yahoo.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>


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


Mime
View raw message