You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by sergarci <se...@gmail.com> on 2014/05/19 17:14:11 UTC
CSV bindy
Hi there
I'm running some examples with camel and csv bindy.
I'm having trouble with some CSV files wich first colum is not a number, for
ecample a Date or a String, it always throws
"java.lang.NumberFormatException".
I've read the Bindy wiki
(https://cwiki.apache.org/confluence/display/CAMEL/Bindy) but I do't find
any help.
I can't change the csv format.
Any suggestions?
--
View this message in context: http://camel.465427.n5.nabble.com/CSV-bindy-tp5751292.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: CSV bindy
Posted by sergarci <se...@gmail.com>.
Hi everyone
I forgot telling what my error was.
It makes me feel stupid...
The think is that I just needed to use an object factory that creates my
model class:
@XmlRegistry
public class ObjectFactory {
public MyClass createMyClass() {
return new MyClass();
}
}
And that's it.
Thanks you all!
--
View this message in context: http://camel.465427.n5.nabble.com/CSV-bindy-tp5751292p5753994.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: CSV bindy
Posted by sergarci <se...@gmail.com>.
Thanks I'll try it this way!
--
View this message in context: http://camel.465427.n5.nabble.com/CSV-bindy-tp5751292p5751360.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: CSV bindy
Posted by Charles Moulliard <ch...@gmail.com>.
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 <se...@gmail.com> 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
Re: CSV bindy
Posted by sergarci <se...@gmail.com>.
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.
Re: CSV bindy
Posted by Charles Moulliard <ch...@gmail.com>.
Can you provide please more info ? csv that you would like to map + java
code
On Mon, May 19, 2014 at 5:14 PM, sergarci <se...@gmail.com> wrote:
> Hi there
>
> I'm running some examples with camel and csv bindy.
> I'm having trouble with some CSV files wich first colum is not a number,
> for
> ecample a Date or a String, it always throws
> "java.lang.NumberFormatException".
>
> I've read the Bindy wiki
> (https://cwiki.apache.org/confluence/display/CAMEL/Bindy) but I do't find
> any help.
>
> I can't change the csv format.
>
> Any suggestions?
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/CSV-bindy-tp5751292.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