Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Wiki Markup
h2. BeanIO
*Available as of Camel 

BeanIO

...

2.10

...

*

The BeanIO [Data Format] uses [BeanIO|http://beanio.org/] to handle flat payloads (such as XML, CSV, delimited, or fixed length formats).

...

Options

Option

Type

Description

config

CSVConfig

Can be used to set a custom CSVConfig object.

TODO:

Usage

TODO:

Dependencies

To use BeanIO in your camel routes you need to add the a dependency on camel-beanio which implements this data format.

If you use maven you could just add the following to your pom.xml, substituting the version number for the latest & greatest release (see the download page for the latest versions).

Code Block
xmlxml


BeanIO is configured using a [mappings XML|http://beanio.org/2.0/docs/reference/index.html#TheMappingFile] file where you define the mapping from the flat format to Objects (POJOs). This mapping file is mandatory to use.

h3. Options
{div:class=confluenceTableSmall}
|| Option || Default || Description ||
| mapping | | The BeanIO mapping file. The option is mandatory. Is by default loaded from the classpath. You can prefix with {{file:}}, {{http:}}, or {{classpath:}} to denote from where to load the mapping file. |
| streamName | | The name of the stream to use. This option is mandatory. |
| ignoreUnidentifiedRecords | {{false}} | Whether to ignore unidentified records. |
| ignoreUnexpectedRecords | {{false}} | Whether to ignore unexpected records. |
| ignoreInvalidRecords | {{false}} | Whether to ignore invalid records. |
| encoding | Platform default | The charset to use. |
{div}

h3. Usage

An example of a [mapping file is here|https://svn.apache.org/repos/asf/camel/trunk/components/camel-beanio/src/test/resources/org/apache/camel/dataformat/beanio/mappings.xml].

h4. Using Java DSL
To use the {{BeanIODataFormat}} you need to configure the data format with the mapping file, as well the name of the stream.
In Java DSL this can be done as shown below. The streamName is "employeeFile".

Then we have two routes. The first route is for transforming CSV data into a List<Employee> Java objects. Which we then [split|Splitter], so the mock endpoint
receives a message for each row.

The 2nd route is for the reverse operation, to transform a List<Employee> into a stream of CSV data.
{snippet:id=e1|lang=java|url=camel/trunk/components/camel-beanio/src/test/java/org/apache/camel/dataformat/beanio/BeanIODataFormatSimpleTest.java}

The CSV data could for example be as below:
{snippet:id=e2|lang=java|url=camel/trunk/components/camel-beanio/src/test/java/org/apache/camel/dataformat/beanio/BeanIODataFormatSimpleTest.java}

h4. Using XML DSL
To use the BeanIO data format in XML, you need to configure it using the <beanio> XML tag as shown below. The routes is similar to the example above.
{snippet:id=e1|lang=xml|url=camel/trunk/components/camel-beanio/src/test/resources/org/apache/camel/dataformat/beanio/SpringBeanIODataFormatSimpleTest.xml}

h3. Dependencies

To use BeanIO in your camel routes you need to add the a dependency on *camel-beanio* which implements this data format. 

If you use maven you could just add the following to your pom.xml, substituting the version number for the latest & greatest release (see [the download page for the latest versions|Download]).

{code:xml}
<dependency>
  <groupId>org.apache.camel</groupId>
  <artifactId>camel-beanio</artifactId>
  <version>2.10.0</version>
</dependency>
{code}