commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Rose <hpartyma...@yahoo.com>
Subject Re: [BeanUtils]: describe method bug with array as bean property
Date Fri, 25 Apr 2003 14:55:31 GMT

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...

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

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


Mime
View raw message