BeanIO
Since Camel 2.10
The BeanIO Data Format uses BeanIO to handle flat payloads (such as XML, CSV, delimited, or fixed length formats).
BeanIO is configured using a mappings XML file where you define the mapping from the flat format to Objects (POJOs). This mapping file is mandatory to use.
Options
The BeanIO dataformat supports 8 options, which are listed below.
Name | Default | Java Type | Description |
---|---|---|---|
|
Required The BeanIO mapping file. Is by default loaded from the classpath. You can prefix with file:, http:, or classpath: to denote from where to load the mapping file. |
||
|
Required The name of the stream to use. |
||
|
Whether to ignore unidentified records. |
||
|
Whether to ignore unexpected records. |
||
|
Whether to ignore invalid records. |
||
|
The charset to use. Is by default the JVM platform default charset. |
||
|
To use a custom org.apache.camel.dataformat.beanio.BeanIOErrorHandler as error handler while parsing. Configure the fully qualified class name of the error handler. Notice the options ignoreUnidentifiedRecords, ignoreUnexpectedRecords, and ignoreInvalidRecords may not be in use when you use a custom error handler. |
||
|
This options controls whether to unmarshal as a list of objects or as a single object only. The former is the default mode, and the latter is only intended in special use-cases where beanio maps the Camel message to a single POJO bean. |
Usage
An example of a mapping file is here.
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, 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.
The CSV data could for example be as below:
Dependencies
To use BeanIO in your Camel routes you need to add a dependency on camel-beanio which implements this data format.
If you use Maven you can 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).
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-beanio</artifactId>
<version>2.10.0</version>
</dependency>
Spring Boot Auto-Configuration
When using beanio with Spring Boot make sure to use the following Maven dependency to have support for auto configuration:
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-beanio-starter</artifactId>
<version>x.x.x</version>
<!-- use the same version as your Camel core version -->
</dependency>
The component supports 9 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
To use a custom org.apache.camel.dataformat.beanio.BeanIOErrorHandler as error handler while parsing. Configure the fully qualified class name of the error handler. Notice the options ignoreUnidentifiedRecords, ignoreUnexpectedRecords, and ignoreInvalidRecords may not be in use when you use a custom error handler. |
String |
||
Whether to enable auto configuration of the beanio data format. This is enabled by default. |
Boolean |
||
The charset to use. Is by default the JVM platform default charset. |
String |
||
Whether to ignore invalid records. |
false |
Boolean |
|
Whether to ignore unexpected records. |
false |
Boolean |
|
Whether to ignore unidentified records. |
false |
Boolean |
|
The BeanIO mapping file. Is by default loaded from the classpath. You can prefix with file:, http:, or classpath: to denote from where to load the mapping file. |
String |
||
The name of the stream to use. |
String |
||
This options controls whether to unmarshal as a list of objects or as a single object only. The former is the default mode, and the latter is only intended in special use-cases where beanio maps the Camel message to a single POJO bean. |
false |
Boolean |