Unmarshal a CSV file with Apache Camel

Today I tried to work with Apache Camel for the first time. I'm currently reading the book Camel in Action and want to try the example with data that has a meaning to me. I decided to follow the examples of Chapter 3: Transforming data with Camel and try to read rows from a CSV file and convert them with Bindy into annotated POJOs.

But, oh boy, is the documentation lacking. And the book is not helping me at all at this point. The examples there look easy and when you're reading the book you can follow the thoughts. But when I actually tried to write my first unit test without pasting the whole examples into your project, I got lost. The documentation of Bindy is very confusing if you only start writing tests for Camel. And the examples tests they show in the docs are so complicated I couldn't strip them down to a minimal version that would just read the CSV and unmarshal the rows into POJOs.

And what do you do if you can't figure out how to do stuff? You post a question on StackOverflow.

And right after I posted that question, I got the test running. Isn't it always like that? As soon as you ask for help, you find the solution to your problem. As if I'm afraid to let others see how much I suck. Anyway, here is a working junit test that will unmarshal a CSV into POJOs with the use of an annotated java bean:



You can get the complete example in this gist.

The confusing thing is that I don't get a list of CsvBeans, but a list of Maps that have an entry with the key set to the name of my class and the value set to the actual unmarshalled CsvBean. That was a surprise, and I don't know yet what that means. I think there's more to the CSV than I can see now, maybe having multiple bean classes unmarshalled from the CSV when there is a different number of columns in the rows.


Weitere Artikel

Crossfit Open WOD 17.5

Crossfit Open WOD 17.4

Crossfit Open WOD 17.3

Crossfit Open Workout 17.2

Crossfit Open Workout 17.1

Run Feedbin in your local Kubernetes cluster

Running Threema Web in Docker

Neues Workout Video

Diät Update #1

Workout 21.01.2017