apache camel csv or excel parser

Jackie
1 min readJul 28, 2020

default camel csv parsing method, wont keep the header row. http://camel.apache.org/csv.html

from("direct:start").

marshal().csv().

to("mock:result");

it would convert the collection into list of comma separated rows, however, the header of the row is not kept.

something like

630205,1111598,1,41848.040000

630210,1111603,1,8726.240000

to keep the header, one solution is to use the camel bindy.

DataFormat bindy = new

BindyCsvDataFormat("com.blk.autoTest.bindy");

.beanRef("COMDailyProdReportService","process")//use this service class to get the result set

//set the body as list of map ?

//the header would be lost after marshal

.marshal(bindy)

//.csv()

.beanRef("COMDailyProdReportService","check")

and the bindy class, specify: (generateHeaderColumns=true)

@CsvRecord(separator ="," , crlf = "UNIX", skipFirstLine = false, generateHeaderColumns=true)

public class COMProdOrders {

}

then results:

orderId,transactionId,direction,amount
630205,1111598,1,41848.040000
630210,1111603,1,8726.240000

https://lwpro2.wordpress.com/2013/05/28/apache-camel-csv-or-excel-parser/

--

--