0
votes

I am reading a csv file using apache camel csv data format and I am unmarshalling the content of the file.

when reading the data I have to remove spaces between column name header.

For example if the column name is "First Name", the space between them should be removed and it should be processed a "FirstName".

CsvDataFormat csvdataformat = new CsvDataFormat();
csvdataformat.setSkipHeaderRecord(true);
csvdataformat.setUseMaps(true);

from("file:/folder1/?fileName=sample.csv")
            .routeId("samplerouteid")
            .autoStartup(false)
            .unmarshal(csvdataformat)
            .process(new Processor() {
                @Override
                public void process(Exchange exchange) throws Exception {
                    /*code to process data*/
                }
            });

How to achieve this using Apache Camel CSV ?

1

1 Answers

0
votes

Which version of Camel are you using? in 2.15 you have the option of overriding the header names, defining you own header.

header String[]
Overrides the header of the reference format.

This option is null by default. When null it keeps the value of the reference format which is null for CSVFormat.DEFAULT. In the XML DSL, this option is configured using children tags:

<csv >
    <header>orderId</header>
    <header>amount</header>
</csv>

This documentation is available in the Camel web site. We have encountered the same problem and we could solve it using the header. We use XML DSL but should be the same using Java.