Camel Components

CBOR

Since Camel 3.0

CBOR is a Data Format that uses the Jackson library with the CBOR extension to unmarshal a CBOR payload into Java objects or to marshal Java objects into a CBOR payload.

  • Java

  • XML

  • YAML

from("activemq:My.Queue")
    .unmarshal().cbor()
    .to("mqseries:Another.Queue");
<route>
  <from uri="activemq:My.Queue"/>
  <unmarshal><cbor/></unmarshal>
  <to uri="mqseries:Another.Queue"/>
</route>
- route:
    from:
      uri: activemq:My.Queue
      steps:
        - unmarshal:
            cbor: {}
        - to:
            uri: mqseries:Another.Queue

Usage

CBOR Options

The CBOR dataformat supports the following options which are listed below.

Name Default Java Type Description

objectMapper (advanced)

String

Lookup and use the existing CBOR ObjectMapper with the given id when using Jackson.

useDefaultObjectMapper (common)

true

Boolean

Whether to lookup and use default Jackson CBOR ObjectMapper from the registry.

unmarshalType (common)

String

Class name of the java type to use when unmarshalling.

collectionType (advanced)

String

Refers to a custom collection type to lookup in the registry to use.

useList (common)

false

Boolean

To unmarshal to a List of Map or a List of Pojo.

allowUnmarshallType (common)

false

Boolean

If enabled then Jackson CBOR is allowed to attempt to use the CamelCBORUnmarshalType header during the unmarshalling.

prettyPrint (common)

false

Boolean

To enable pretty printing output nicely formatted. Is by default false.

allowJmsType (advanced)

false

Boolean

Used for JMS users to allow the JMSType header from the JMS spec to specify a FQN classname to use to unmarshal to.

enableFeatures (advanced)

String

Set of features to enable on the Jackson ObjectMapper. Multiple features can be separated by comma.

disableFeatures (advanced)

String

Set of features to disable on the Jackson ObjectMapper. Multiple features can be separated by comma.

Message Body

The message body at each side of the CBOR data format: Marshal input and Unmarshal input are the bodies marshal and unmarshal can take, and Marshal output and Unmarshal output the body after them.

Side Body Description

Marshal input

map, list or pojo

A Map, a List or a POJO to write as CBOR. A String or bytes are written as one CBOR text or byte string, not as they are.

Marshal output

stream, as binary

The CBOR data in the stream cache, or a byte array when stream caching is off.

Unmarshal input

bytes, stream or file, as binary

CBOR data. A String fails.

Unmarshal output

map or list

A Map (LinkedHashMap) for a CBOR map, a List (ArrayList) for an array; an object of the class unmarshalType names.

  • With useList=true: list

Not known when unmarshalType or collectionType or allowUnmarshallType or allowJmsType is set.

The bodies are the ones with the default options. A side that is not listed is not known, and tooling does not guess it. The carriers are described in the Camel Catalog.

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.

XML-only: Spring XML data format configuration
<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" unmarshalType="org.apache.camel.component.cbor.TestPojo"/>
</dataFormats>

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

  • Java

  • XML

  • YAML

from("direct:back")
    .unmarshal("test")
    .to("mock:reverse");
<route>
    <from uri="direct:back"/>
    <unmarshal><custom ref="test"/></unmarshal>
    <to uri="mock:reverse"/>
</route>
- route:
    from:
      uri: direct:back
      steps:
        - unmarshal:
            custom:
              ref: test
        - to:
            uri: mock:reverse

Dependencies

<dependency>
   <groupId>org.apache.camel</groupId>
   <artifactId>camel-cbor</artifactId>
   <version>x.x.x</version>
</dependency>