You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Piotr Dudkiewicz (JIRA)" <ji...@apache.org> on 2019/07/19 14:02:00 UTC
[jira] [Commented] (CONFIGURATION-733) Attribute value cannot
delimit to list
[ https://issues.apache.org/jira/browse/CONFIGURATION-733?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16888887#comment-16888887 ]
Piotr Dudkiewicz commented on CONFIGURATION-733:
------------------------------------------------
The problem is that the ListDelimiterHandler is hardcoded to DisabledListDelimiterHandler in DefaultConversionHandler.
It doesn't use builder setting.
As a workaround I had to implement my own conversion handler.
{code:java}
package org.apache.commons.configuration2.convert;
import java.util.Collection;
public class LegacyConversionHandler extends DefaultConversionHandler {
private static final LegacyListDelimiterHandler LIST_DELIMITER_HANDLER = new LegacyListDelimiterHandler(',');
@Override
protected Collection<?> extractValues(Object source, int limit) {
return LIST_DELIMITER_HANDLER.flatten(source, limit);
}
}
{code}
> Attribute value cannot delimit to list
> --------------------------------------
>
> Key: CONFIGURATION-733
> URL: https://issues.apache.org/jira/browse/CONFIGURATION-733
> Project: Commons Configuration
> Issue Type: Bug
> Affects Versions: 2.4
> Reporter: Hao Chen
> Priority: Major
>
> Given the following configuration XML:
> <configuration>
> <header>
> <result throwExceptionOnMissing="true">
> <listDelimiterHandler config-class="org.apache.commons.configuration2.convert.DefaultListDelimiterHandler">
> <config-constrarg config-value=","/>
> </listDelimiterHandler>
> </result>
> </header>
> <node type="test" types="a,b,c"/>
> </configuration>
> With the following test code:
> Parameters params = new Parameters();
> ReloadingFileBasedConfigurationBuilder<XMLConfiguration> builder = new ReloadingFileBasedConfigurationBuilder<XMLConfiguration>(XMLConfiguration.class);
> builder.configure(params.xml().setFile(file).setListDelimiterHandler(new DefaultListDelimiterHandler(',')));
> XMLConfiguration configuration = builder.getConfiguration();
> List<String> types = configuration.getList(String.class, "node[@types]");
> // result WRONG -- returns ["a,b,c"]
> org.junit.Assert.assertEquals(types.size(), 3);
> I just couldn't find any way to get the attribute value as a comma-delimited list...
> In general, the default behavior change for list delimiter is a big headache while we are trying to upgrade to commons-configuration2...
--
This message was sent by Atlassian JIRA
(v7.6.14#76016)