This Confluence has been LDAP enabled, if you are an ASF Committer, please use your LDAP Credentials to login. Any problems file an INFRA jira ticket please.

Child pages
  • YAML Data Format
Skip to end of metadata
Go to start of metadata

YAML

YAML is a Data Format to marshal and unmarshal Java objects to and from YAML.

For YAML to object marshalling, Camel provides integration with three popular YAML libraries:

Every library requires adding the special camel component (see "Dependency..." paragraphs further down). By default Camel uses the SnakeYAML library.

Using YAML data format with the SnakeYAML library

// lets turn Object messages into yaml then send to MQSeries
from("activemq:My.Queue")
  .marshal().yaml()
  .to("mqseries:Another.Queue");
// lets turn Object messages into yaml then send to MQSeries
from("activemq:My.Queue")
  .marshal().yaml(YAMLLibrary.SnakeYAML)
  .to("mqseries:Another.Queue");

Using YAML 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.

        <dataFormats>
            <!-- here we define a YAML data format with the id snak and that it should use the TestPojo as the class type when
                 doing unmarshal. The unmarshalTypeName is optional, if not provided Camel will use a Object.class as the type -->
            <yaml id="snake" library="SnakeYAML" unmarshalTypeName="org.apache.camel.component.yaml.model.TestPojo"/>
        </dataFormats>

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

       <route>
            <from uri="direct:back"/>
            <unmarshal ref="snake"/>
            <to uri="mock:reverse"/>
        </route>

 

Options for SnakeYAML Data Format

Name

Type

Default

Description

unmarshalType

Class

Object.class

Class of the object to be created
classLoader
ClassLoadernullThe classloader to use to instantiate objects
constructor
StringnullA reference to an
org.yaml.snakeyaml.constructor.BaseConstructor instance in the registry
representer
StringnullA reference to an
org.yaml.snakeyaml.representer.Representer instance in the registry
dumperOptions
StringnullA reference to an
org.yaml.snakeyaml.DumperOptions instance in the
registry
resolver
StringnullA reference to an
org.yaml.snakeyaml.resolver.Resolver instance in the registry
 
useApplicationContextClassLoader
 Booleantrue To use CamelContext's  
ApplicationContextClassLoader if no custom class loader is set and
ApplicationContextClassLoader is provided
prettyFlow
 Booleanfalse 
Force the emitter to produce a pretty YAML document when using the flow style

 

Dependencies for SnakeYAML

To use YAML in your camel routes you need to add the a dependency on camel-snakeyaml 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).

<dependency>
  <groupId>org.apache.camel</groupId>
  <artifactId>camel-snakeyaml</artifactId>
  <version>${camel-version}</version>
</dependency>

 

 

  • No labels