Name

Marshal — Marshals data into a specified format for transmission over a transport or component

Usage

The Marshal pattern uses Apache Camel's pluggable data format mechanism to convert messages into a format appropriate for transmission by one of the Apache Camel components.

The Marshal pattern can be placed anywhere in the body of a route. However, it is typically placed before endpoints that transmit the message to another location.

Properties

Table 51 describes the properties you can specify using the properties editor.

Table 51. Marshal Properties

NameDescription
Inherit Error Handler Specifies whether the node should use the error handler configured for the route. The default is Disabled.
Data Format Type

Specifies the data type into which the data will be marshalled. For data formats that require configuration, the format's tab provides the property fields to configure the marshaller.

Because the GZip, Serialization, String, and Zip data formats are part of the Camel core, you need not add dependencies for them in your Maven pom.xml file to use them. However, to use any of the other supported data formats, you must add a dependency on the component that implements the data format (for example, camel-protobuf, camel-xmlbeans, camel-flatpack, and so on) in your Maven pom.xml file.

  • avro— Marshals Java Objects into the Apache Avro binary data format using a user-supplied schema that defines message types and a protocol.

  • beanio— Marshals Java Objects into flat data structures according to a user-defined mapping

  • bindy— Marshals Java Objects into flat data structures

  • castor—Marshals Java Objects to XML

  • crypto—Marshals Java Objects to encrypted cyphertext

  • csv—Marshals Java Objects to csv format

  • custom—Marshals Java Objects to a custom data format implemented using the DataFormat interface

  • flatpack—Marshals Java Objects to fixed-width or delimited text messages

  • gzip—Marshals normal, uncompressed messages to gzipped compressed messages

  • hl7—Marshals HL7 HAPI message objects to byte streams

  • jaxb—Marshals Java Objects to XML

  • jibx—Marshals Java Objects to XML using the JiBX library

  • json—Marshals Java Objects to JSON

  • pgp—Marshals Java Objects to encrypted cyphertext

  • protobuf—Marshals Java Objects to Protocol Buffers format (Google's data exchange format)

  • rss—Marshals ROME SyndFeed messages to XML String messages

  • secureXML—Marshals plain XML to encrypted XML. This data format works at the document, element, and element content levels.

  • serialization—Marshals Java Objects to a binary blob using the standard Java serialization mechanism

  • soapjaxb—Marshals a tree of Java Objects to a SOAP message using JAXB and JAX-WS annotations

  • string—Marshals XML or text-based messages to String Objects

  • syslog—Marshals Java String Objects to RFC3164 message format

  • xmlbeans—Marshals Java objects to XML using the XmlBeans library

  • xmljson—Marshals XML directly to Json

  • xstream—Marshals Java objects to XML using the XStream library

  • zip—Marshals normal, uncompressed messages to zipped compressed messages

Ref Specifies a reference to a Spring bean configuring the Apache Camel data format to which the message body is marshalled.
Id Specifies a unique identifier for the endpoint. The Id can be used to refer to the endpoint in the Camel XML file.
Description Specifies a text description for the node. This description is included in the generated XML file, but it is informational only. It is not used by Apache Camel.

avro

Table 52 describes the properties needed to configure the avro marshaller.

Table 52. avro Properties

NameDescription
Instance Class Name Specifies the name of the instance class to use for marshalling. This is the class defined by your schema .apache.camel.dataformat.avro.<nameOfInstanceClass>.

beanio

Table 53 describes the properties needed to configure the beanio marshaller.

Table 53. beanio Properties

NameDescription
Encoding

Specifies the charset to use. The default is platform-specific.

Ignore Invalid Records

Species whether to ignore invalid records. The default is false.

Ignore Unexpected Records Species whether to ignore invalid records. The default is false.
Ignore Unidentified Records Species whether to ignore invalid records. The default is false.
Mapping Specifies the BeanIO mapping.xml file to use. By default, this file is loaded from the classpath, but you can add one of the prefixes—file:, http:, or classpath:—to specify the location from which to load this file.
Stream Name Specifies the name of the stream to use.

bindy

Table 54 describes the properties needed to configure the bindy marshaller.

Table 54. bindy Properties

NameDescription
Class Type

Specifies a fully qualified class name that explicitly defines the type to use for marshalling. For example, you might enter com.mycompany.MyOrder

You must use either this property or Packages, but not both.

Locale

Species the language name of the locale whose date and number format will be used. If not specified, the marshaller determines and uses the formatting of a default language name. Valid values are the two-letter abbreviation of the language name, in lower case. For example,

  • ar—Arabic

  • es—Castilian Spanish

  • da—Danish

  • en—English

  • fr—French

  • jp—Japanese

For an exhaustive list of language names, see Codes for the Representation of Names of Languages

Packages

Specifies the packages to use for marshalling. A package contains a defined model with required annotations properly associated for each class in the model. For example, you might enter com.mycompany.

When specifying multiple packages, separate them with a comma (,).

You must use either this property or Class Type, but not both.

Type Specifies the record type, Select either Csv (comma-separated value fields), Fixed (fixed-length records), or KeyValue (key/value pair fields).

castor

Table 55 describes the properties needed to configure the castor marshaller.

Table 55. castor Properties

NameDescription
Classes Specifies additional classes to add to the Castor XmlContext. Enter the fully qualified path. When specifying multiple classes, separate them with a comma (,).
Encoding Specifies the encoding to use when marshalling an Object to XML. Default is UTF-8.
Mapping File Specifies the path to the Castor mapping file to load from the classpath.
Packages Specifies any additional packages to add to the Castor XmlContext. Enter the fully qualified path. When specifying multiple classes, separate them with a comma (,).

crypto

Table 56 describes the properties needed to configure the crypto marshaller.

Table 56. crypto Properties

NameDescription
Algorithm Specifies the name of the JCE cryptographic algorithm to use. Default is DES/CBC/PKCS5Padding.
Algorithm Parameter Ref Specifies a reference to the JCE AlgorithmParameterSpec to use to initialize the cipher. Some crypto algorithms, particularly block algorithms, require initialization by an initial block of data, known as an Initialization Vector. The JCE passes the Initialization Vector to the cipher as an AlgorithmParameterSpec . Select from the list of available options.
Buffersize Specifies the size, in bytes, of the buffer used in the signature process.
Crypto Provider Specifies the name of the JCE Security Provider to use. For options, see Java Cryptography Architecture; Sun Providers Documentation.
Init Vector Ref Specifies a reference to a byte array containing the Initialization Vector to use to initialize the cipher. Select from the list of available options.
Inline Enables inlining the configured Initialization Vector into the encrypted data stream.
Key Ref Specifies the value of the keyref attribute within the <dataFormats> element in a Spring configuration. For example, <crypto id="basic" algorithm="DES" keyref="desKey" />. Select from the list of available options.
Mac Algorithm Specifies the algorithm to use to create the Hash-based Message Authentication. Default is HmacSHA1. For more options, see Java Standard Names Reference.
Should Append HMAC Enables calculating and appending a Message Authentication Code to the encrypted data.

csv

Table 57 describes the properties needed to configure the csv marshaller.

Table 57. csv Properties

NameDescription
Config Ref Reference to a custom CSVConfig object.
Delimiter Specifies the character to use to separate the fields in a csv record. Default is , (comma). Valid values are any single character, such as ., |, ;, #, and so on.
Strategy Ref Reference to a custom CSVStrategy.

custom

Table 58 describes the properties needed to configure the custom marshaller.

Table 58. custom Properties

NameDescription
Ref Reference to file that implements your custom data format using the DataFormat interface.

jaxb

Table 59 describes the properties needed to configure the jaxb marshaller.

Table 59. jaxb Properties

NameDescription
Context Path Specifies the context path for the jaxb data format. For example, org.apache.camel.example
Encoding

Specifies the encoding to use when marshalling data. Valid values include:

  • ISO-8859-1

  • US-ASCII

  • UTF-8

With no value specified, Red Hat Fuse IDE defaults to the encoding used by JAXB.

Filter Non XML Chars Enables the filtering of non XML characters during marshalling such that the marshaller replaces any non XML characters it encounters with the string " ". Otherwise, when it encounters a non XML character, the marshaller throws an exception.
Fragment Enables the marshaller's FRAGMENT encoding property, which prevents the marshaller from generating the XML declaration. Enable this property in conjunction with setting Part Class and Part Namespace to perform partial marshalling on only a fragment of the XML tree.
Ignore JAXBElement Not Applicable.
Part Class Specifies the uri of the class within the XML tree that you want to marshal, leaving all other classes in the tree as is. Set this property in conjunction with Fragment and Part Namespace to perform partial marshalling on only a fragment of the XML tree.
Part Namespace Specifies the Qname of the destination namespace.
Pretty Print Enables pretty printing, which adds white space as needed to tidy up the resulting XML for easy reading.

json

Table 60 describes the properties needed to configure the json marshaller.

Table 60. json Properties

NameDescription
Library Specifies the library to use for marshalling. Select either XStream or Jackson from the drop-down list. Default is XStream.
Pretty Print Enables pretty printing, which adds white space as needed to tidy up the resulting XML for easy reading.
Unmarshal Type Name Not Applicable.

pgp

Table 61 describes the properties needed to configure the pgp marshaller.

Table 61. pgp Properties

NameDescription
Armored Specifies whether to base64 encode the encrypted text, so it can be copied/pasted, and so on. The default is Disabled.
Integrity Specifies whether to add an integrity check sign to the encrypted file. The default is Enabled.
Key File Name Specifies the name of the keyring file that contains the public keys to use to encrypt the data. This file must be accessible as classpathresource; for example, org/apache/camel/component/crypto/pubring.gpg.
Key User Id Specifies the user id of the key in the pgp keyring used for encryption.
Password Specifies the password to use for opening the private key. This password is not used for encryption.

protobuf

Table 62 describes the properties needed to configure the protobuf marshaller.

Table 62. protobuf Properties

NameDescription
Instance Class Specifies the name of the instance class to use for marshalling. This is one of the classes generated when you compiled your .proto file. Include the builder generated in the uri; for example, org.apache.camel.dataformat.protobuf.generated.<nameOfInstanceClass>.

secureXML

Table 63 describes the properties needed to configure the secureXML marshaller.

Table 63. secureXML Properties

NameDescription
Key Cipher Algorithm [a]

Specifies the cipher algorithm to use to encrypt the asymmetric key. Default is null. Valid values are:

  • XMLCipher.RSA_v1dot5

  • XMLCipher.RSA_OAEP

Asymmetric key encryption is enabled when either this property is set, or the Recipient Key Alias property is set.

Key Or Trust Store Parameters Id [a] Specifies the ID of the configuration options to use to create and load a keyStore instance that represents the sender's trustStore, when performing asymmetric key encryption.
Key Password Specifies the password to use for retrieving the private key from the keystore, when performing asymmetric decryption.
Pass Phrase Specifies a string of alphanumeric characters to use as the passphrase for marshalling the message into cyphertext. The passphrase must be appropriate for the selected encryption algorithm. if not, the marshaller throws an exception. When no phrase is specified, the marshaller generates and uses a default passphrase.
Recipient Key Alias [a] Specifies the key alias to use for retrieving the recipient's public or private key from a KeyStore when performing asymmetric key encryption.
Secure Tag Specifies the XPath reference to the XML element to encrypt. If left blank, the entire XML message is encrypted.
XML Cipher Algorithm

Specifies the cipher algorithm to use for encrypting message content. Valid values include:

  • XMLCipher.TRIPLIDES [Default]

  • XMLCipher.AES_128

  • XMLCipher.AES_192

  • XMLCipher.AES_256

[a] Used for asymmetric key encryption


soapjaxb

Table 64 describes the properties needed to configure the soapjaxb marshaller.

Table 64. soapjaxb Properties

NameDescription
Context Path Specifies the path of the package to use for initializing the JAXB context.
Element Name Strategy Ref Specifies the bean reference to use to the element name and its namespace within the body of the soap message. Select for the list of available options.
Encoding

Specifies the encoding to use when marshalling data. Valid values include:

  • ISO-8859-1

  • US-ASCII

  • UTF-8

With no value specified, Red Hat Fuse IDE defaults to the encoding used by JAXB.

Version Specifies the version of soap to use. Options are 1.1 or 1.2; the default is 1.1.

string

Table 65 describes the properties needed to configure the string marshaller.

Table 65. string Properties

NameDescription
Charset

Specifies the character set to use for encoding. Valid values include:

  • ISO-8859-1

  • US-ASCII

  • UTF-8

With no value specified, Red Hat Fuse IDE defaults to the encoding used by the platform.


XmlBeans

Table 66 describes the properties needed to configure the XmlBeans marshaller.

Table 66. XmlBeans Properties

NameDescription
Pretty Print Enables pretty printing, which adds white space as needed to tidy up the resulting XML for easy reading.

Xmljson

Table 67 describes the properties needed to configure the xmljson marshaller.

[Note]Note

An asterisk (*) to the right of a property name (marshaller properties only) indicates that the default value for that property is set by json-lib, not by the code of the data format.

Table 67. xmljson Properties

NameDescription
Array Name

Applies to unmarshalling only.

Element Name

Applies to unmarshalling only.

Encoding

Applies to unmarshalling only.

For marshalling, encoding is determined by the input String being processed. When converting an input Stream, json-lib uses the platform's default encoding.

Expandable Properties Applies to unmarshalling only.
Force Top Level Object *

Specifies whether the resulting json conversion starts off with a top-most element whose name matches the XML root element.

When disabled (default), the xml string <a><x>1</x><y>2</y><a> is converted to {'x:'1','y':'2'}; otherwise it's converted to {'a':'x:'1','y':'2'}}.

Namespace Lenient Applies to unmarshalling only.
Remove Namespace Prefixes *

Specifies whether to remove the namespace prefixes from XML-qualified elements so that the resulting json string does not contain them.

The default is false.

Root Name

Applies to unmarshalling only.

Skip Namespaces *

Specifies whether namespaces are ignored. When disabled (default), they are added to the json output using @xmlns elements.

Skip Whitespace * Specifies whether white spaces between XML elements are treated as text values or are ignored. When disabled (default), they are treated as text values.
Trim Spaces * Specifies whether leading and trailing white spaces are omitted in string values. When disabled (default), they are left untouched.
Type Hints Applies to unmarshalling only.

zip

Table 68 describes the properties needed to configure the zip marshaller.

Table 68. zip Properties

NameDescription
Compression Level

Specifies the level of compression for the marshaller to use. When no value is specified, the marshaller uses its default compression algorithm. Valid values are:

  • deflater.BEST_SPEED

    Conservative compression, optimized for speed.

  • deflater.BEST_COMPRESSION

    Aggressive compression, slowest speed.

  • deflater.DEFAULT_COMPRESSION

    Moderate compression, moderate speed.


Related topics

Adding beans and configuration