commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alessio Pace <alessio.p...@gmail.com>
Subject Re: [Digester] Digester does not seem to me to make use of StringArrayConverter (Test case here)
Date Thu, 05 Jan 2006 11:48:58 GMT
Well, so here 2 tests, hope it is what you meant:

-the first uses ConvertUtils and passes
-the second uses BeanUtils and fails

public void testConvertUtilsItself() throws Exception{
		String authorsAsString = "First,Second";
		Object result = ConvertUtils.convert(authorsAsString, new String[]
{}.getClass());
		String[] authorsAsArray = (String[]) result;
		System.out.println("Array size: "+ authorsAsArray.length + " |
content: " + Arrays.deepToString(authorsAsArray));
		assertEquals(2, authorsAsArray.length);  // assert 2 authors: OK
}
	
public void testBeanUtils() throws Exception {
		Book book = new Book();
		BeanUtils.setProperty(book, "authors", "{First,Second}");
		String[] authorsAsArray =  book.getAuthors();
		System.out.println("Array size: "+ authorsAsArray.length + " |
content: " + Arrays.deepToString(authorsAsArray));
		assertEquals(2, authorsAsArray.length);  // assert 2 authors: FAILS
		
}

In both cases the setter whose parameter is a String[] is called, in
the first case correctly passing a 2 length string array {"First",
"Second"}, in the second case a 1 length string arrat
{"First,Second"}.

I am really not an expert of the commons-beanutils but those 2
different beahviours seem a little strange to me.

Alessio Pace



On 1/5/06, Simon Kitching <skitching@apache.org> wrote:
> On Wed, 2006-01-04 at 18:40 +0100, Alessio Pace wrote:
> > Hi, in my last post I was trying to dig into the String to String[]
> > conversion with no success.
> >
> > So, I splitted it up and did a test case to try to figure out what's wrong.
>
> The BeanPropertySetterRule does the invocation with this line of code:
>
>     BeanUtils.setProperty(top, property, bodyText);
>
> Where "top" is the object the property is being set on, "property" is a
> string containing the name of the javabean property and "bodyText" is
> the string to be converted and passed to the property.
>
> Could you try your example on that? If this correctly invokes
> ConvertUtils then there is a problem with Digester. If not, there is a
> problem with BeanUtils (or your converter).
>
> Regards,
>
> Simon
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>

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


Mime
View raw message