[
https://issues.apache.org/jira/browse/BEANUTILS-359?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Niall Pemberton resolved BEANUTILS-359.
---------------------------------------
Resolution: Won't Fix
The problem in BeanUtils 1.7.0 was that in BeanUtils's setProperty() method if
the destination type was a String array and the value was a String then a
String array with length of 1 was created and the value set to the first
instance of that String *before* convert utils had a chance to delegate to a
converter:
{code}
} else if (value instanceof String) {
String values[] = new String[1];
values[0] = (String) value;
newValue = getConvertUtils().convert((String[]) values, type);
} else if (....) {
{code}
...which is why you had to do hacks like you have in your SimplePojoData's
setJcrMixinTypes() method to split the first occurrence of the String array
being set:
{code}
public void setJcrMixinTypes(String[] mixinTypes) {
if (null != mixinTypes && mixinTypes.length == 1) {
jcrMixinTypes = mixinTypes[0].split(" *, *");
}
}
{code}
In BeanUtils 1.8.0 we changed the behaviour so that the conversion of the
String --> String[] is now handled by the converter registered for String
arrays (see BEANUTILS-258). So now you can either change how the
ArrayConverter for String[] is configured (or register your own converter
implementation for String arrays). In this case if you add colon to the
*allowedCharacters* then you should see the behaviour you want:
{code}
ArrayConverter converter = new ArrayConverter(String[].class, new
StringConverter());
converter.setAllowedChars(new char[] {'.', '-', ':'});
ConvertUtils.register(converter, String[].class);
{code}
Then you can remove the nasty hack from your SimplePojoData's
setJcrMixinTypes() method:
{code}
public void setJcrMixinTypes(String[] mixinTypes) {
this.jcrMixinTypes = mixinTypes;
}
{code}
Alternatively you could create a converter implementation that does what
BeanUtils 1.7.0 did - create a String array with a length of 1 and set the
String value to the first element - then you can leave your hack in
SimplePojoData unchanged.
Closing this as WONTFIX since its working as intended.
> Difference in setProperty() behavior when invoking setter with a String value
> that has ':'
> ------------------------------------------------------------------------------------------
>
> Key: BEANUTILS-359
> URL: https://issues.apache.org/jira/browse/BEANUTILS-359
> Project: Commons BeanUtils
> Issue Type: Bug
> Affects Versions: 1.8.0
> Environment: JDK6
> Reporter: Boni Gopalan
> Fix For: 1.8.1
>
> Attachments: beanutils-test.zip
>
>
> The behavior of BeanUtils.setProperty differes from 1.7.0 when invoking
> setter with a string value that has a : or any other common seperator.
> 1.8.0 --> BeanUtils.setProperty(simplePojo, "jcrMixinTypes",
> "mix:rereferencible"); Splits mix:referensible to new
> String[]{"mix","referencible"}
> 1.7.0 --> BeanUtils.setProperty(simplePojo, "jcrMixinTypes",
> "mix:rereferencible"); Splits mix:referensible to new
> String[]{"mix:referencible"}
> I have a failing testcase that I am atatching. Please run with
> mvn clean test -Dbeanutils.version=1.8.0 ==> for using 1.8.0 version
> mvn clean test -Dbeanutils.version=1.7.0 ==> for using 1.7.0 version
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.