Your project works very well
Camel Route :
<camelContext xmlns="http://camel.apache.org/schema/spring">
<dataFormats>
<bindy type="Csv" packages="my.cool" id="bindyDataformat"/>
</dataFormats>
<route>
<from uri="file:src/data?noop=true"/>
<log message="Begin myRoute from file : ${body}"/>
<unmarshal ref="bindyDataformat"/>
<log message="CSV record marshalled"/>
<marshal ref="bindyDataformat"/>
<log message=">> Record : ${body}"/>
</route>
</camelContext>
Model
import org.apache.camel.dataformat.bindy.annotation.CsvRecord;
import org.apache.camel.dataformat.bindy.annotation.DataField;
import java.math.BigDecimal;
@CsvRecord(separator = ",", skipFirstLine = false)
public class Model {
@DataField(pos = 1)
private String str1;
@DataField(pos = 2)
private String str2;
@DataField(pos = 3)
private String str3;
@DataField(pos = 4, precision = 2)
private BigDecimal amount;
}
Result :
[pache.camel.spring.Main.main()] SpringCamelContext INFO
Apache Camel 2.13.1 (CamelContext: camel-1) started in 0.269 seconds
[1) thread #0 - file://src/data] route1 INFO Begin
myRoute from file : some_string,some_other_string,other_one,121657.56
[1) thread #0 - file://src/data] route1 INFO CSV
record marshalled
[1) thread #0 - file://src/data] route1 INFO >>
Record : some_string,some_other_string,other_one,121657.56
On Tue, May 20, 2014 at 8:03 AM, sergarci <[email protected]> wrote:
> Yes here is an example:
>
> *The file looks like:*
>
> some_string,some_other_string,other_one,121657.56
>
> *the java class that maps the csv file:*
>
> @CsvRecord(separator = ",", skipFirstLine = true)
> public class MyClass {
> @DataField(pos = 1)
> private String str1;
> @DataField(pos = 2)
> private String str2;
> @DataField(pos = 3)
> private String str3;
> @DataField(pos = 4, precision = 2)
> private BigDecimal amount;
> /*getters and setters*/
> }
>
> *And the spring route is like:*
>
> <route id="myRoute">
> <from
> uri="file:///Inbox?noop=true&fileName=someCSV&consumer.delay=10000"
> />
> <log message="Begin myRoute"/>
> <unmarshal ref="bindyDataformat" >
> <bindy type="Csv" classType="my.package.MyClass" />
> </unmarshal>
> ...
> </route>
>
> Thanks!
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/CSV-bindy-tp5751292p5751323.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
--
Charles Moulliard
Apache Committer / Architect @RedHat
Twitter : @cmoulliard | Blog : http://cmoulliard.github.io