apache camel csv or excel parser

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

Advertisements

Author: lwpro2

Java J2EE professional

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s