[
https://issues.apache.org/activemq/browse/CAMEL-1513?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Claus Ibsen updated CAMEL-1513:
-------------------------------
Fix Version/s: 2.0.0
> camel-csv : mutliple messages lead to repeated values
> -----------------------------------------------------
>
> Key: CAMEL-1513
> URL: https://issues.apache.org/activemq/browse/CAMEL-1513
> Project: Apache Camel
> Issue Type: Bug
> Components: camel-core
> Affects Versions: 2.0-M1
> Reporter: Julien Faissolle
> Assignee: Claus Ibsen
> Priority: Minor
> Fix For: 2.0.0
>
>
> I have this config :
> {code:xml}
> <route>
> <from uri="direct:msgIn"/>
> <marshal><csv /></marshal>
> <to uri="file://msgs?fileName=messages.csv" />
> </route>
> {code}
> I send Map objects with this :
> {code:java}
> ProducerTemplate template = context.createProducerTemplate();
> Map msg1 = new HashMap();
> msg1.put("A", 1);
> msg1.put("B", 1);
> Map msg2 = new HashMap();
> msg2.put("A", 2);
> msg2.put("B", 2);
> template.sendBody("direct:msgIn", msg1);
> template.sendBody("direct:msgIn", msg2);
> {code}
> This produces the following result :
> {code}
> 1,1
> 2,2,2,2
> {code}
> instead of
> {code}
> 1,1
> 2,2
> {code}
> The more messages are pumped into the CSV marshaller, the more the values are
> repeated. This is because the marshal method in CsvDataFormat keeps adding
> columns to the config even if they are already present :
> {code:java|title=CsvDataFormat.java}
> ........
> CSVConfig conf = getConfig();
> // lets add fields
> Set set = map.keySet();
> for (Object value : set) {
> if (value != null) {
> String text = value.toString();
> CSVField field = new CSVField(text);
> conf.addField(field);
> }
> }
> CSVWriter writer = new CSVWriter(conf);
> .......
> {code}
> I think the marshal method should perform something like
> {code:java}
> if (config == null) {
> config = createConfig();
> // lets add fields
> Set set = map.keySet();
> for (Object value : set) {
> if (value != null) {
> ..............
> }
> {code}
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.