[[cbor-dataformat]]
== CBOR DataFormat

*Available as of Camel version 3.0*

CBOR is a Data Format which uses the
http://wiki.fasterxml.com/JacksonHome/[Jackson library] with the
https://github.com/FasterXML/jackson-dataformats-binary/tree/master/cbor[CBOR extension]
to unmarshal a CBOR payload into Java objects or to marshal Java objects
into a CBOR payload.

[source,java]
-------------------------------
from("activemq:My.Queue").
  unmarshal().cbor().
  to("mqseries:Another.Queue");
-------------------------------

### CBOR Options

// dataformat options: START
The CBOR dataformat supports 7 options, which are listed below.



[width="100%",cols="2s,1m,1m,6",options="header"]
|===
| Name | Default | Java Type | Description
| objectMapper |  | String | Lookup and use the existing CBOR ObjectMapper with the given id when using Jackson.
| useDefaultObjectMapper | true | Boolean | Whether to lookup and use default Jackson CBOR ObjectMapper from the registry.
| unmarshalTypeName |  | String | Class name of the java type to use when unarmshalling
| collectionTypeName |  | String | Refers to a custom collection type to lookup in the registry to use. This option should rarely be used, but allows to use different collection types than java.util.Collection based as default.
| useList | false | Boolean | To unarmshal to a List of Map or a List of Pojo.
| allowUnmarshallType | false | Boolean | If enabled then Jackson CBOR is allowed to attempt to use the CamelCBORUnmarshalType header during the unmarshalling. This should only be enabled when desired to be used.
| contentTypeHeader | false | Boolean | Whether the data format should set the Content-Type header with the type from the data format if the data format is capable of doing so. For example application/xml for data formats marshalling to XML, or application/json for data formats marshalling to JSon etc.
|===
// dataformat options: END
// spring-boot-auto-configure options: START
=== Spring Boot Auto-Configuration

When using Spring Boot make sure to use the following Maven dependency to have support for auto configuration:

[source,xml]
----
<dependency>
  <groupId>org.apache.camel</groupId>
  <artifactId>camel-cbor-starter</artifactId>
  <version>x.x.x</version>
  <!-- use the same version as your Camel core version -->
</dependency>
----


The component supports 8 options, which are listed below.



[width="100%",cols="2,5,^1,2",options="header"]
|===
| Name | Description | Default | Type
| *camel.dataformat.cbor.allow-unmarshall-type* | If enabled then Jackson CBOR is allowed to attempt to use the CamelCBORUnmarshalType header during the unmarshalling. This should only be enabled when desired to be used. | false | Boolean
| *camel.dataformat.cbor.collection-type-name* | Refers to a custom collection type to lookup in the registry to use. This option should rarely be used, but allows to use different collection types than java.util.Collection based as default. |  | String
| *camel.dataformat.cbor.content-type-header* | Whether the data format should set the Content-Type header with the type from the data format if the data format is capable of doing so. For example application/xml for data formats marshalling to XML, or application/json for data formats marshalling to JSon etc. | false | Boolean
| *camel.dataformat.cbor.enabled* | Whether to enable auto configuration of the cbor data format. This is enabled by default. |  | Boolean
| *camel.dataformat.cbor.object-mapper* | Lookup and use the existing CBOR ObjectMapper with the given id when using Jackson. |  | String
| *camel.dataformat.cbor.unmarshal-type-name* | Class name of the java type to use when unarmshalling |  | String
| *camel.dataformat.cbor.use-default-object-mapper* | Whether to lookup and use default Jackson CBOR ObjectMapper from the registry. | true | Boolean
| *camel.dataformat.cbor.use-list* | To unarmshal to a List of Map or a List of Pojo. | false | Boolean
|===
// spring-boot-auto-configure options: END

#### Using CBOR in Spring DSL

When using Data Format in Spring DSL you need to
declare the data formats first. This is done in the *DataFormats* XML
tag.

[source,xml]
-----------------------------------------------------------------------------------------------------------------------------
        <dataFormats>
            <!-- here we define a CBOR data format with the id test and that it should use the TestPojo as the class type when
                 doing unmarshal. -->
            <cbor id="test" unmarshalTypeName="org.apache.camel.component.cbor.TestPojo"/>
        </dataFormats>
-----------------------------------------------------------------------------------------------------------------------------

And then you can refer to this id in the route:

[source,xml]
-------------------------------------
       <route>
            <from uri="direct:back"/>
            <unmarshal><custom ref="test"/></unmarshal>
            <to uri="mock:reverse"/>
        </route>
-------------------------------------

### Dependencies

[source,java]
-------------------------------------
<dependency>
  <groupId>org.apache.camel</groupId>
  <artifactId>camel-cbor</artifactId>
  <version>x.x.x</version>
</dependency>
-------------------------------------
