Cameleer

String data format

The string data format converts the body to bytes in a chosen charset (marshal) and bytes back to text (unmarshal).

Name: string · Crate: cameleer-core · Cargo feature: none, always included (build features) · Apache Camel: String

When to use it

  • Talk to legacy systems that expect Latin-1 (ISO-8859-1) or ASCII instead of UTF-8.
  • Decode bytes from a socket, a file or a message queue into text before parsing it.
  • Make the byte encoding of a payload explicit.

Marshal and unmarshal

directionbody inbody out
marshaltext (bytes pass through unchanged)bytes in charset. Characters the charset cannot hold become ?.
unmarshalbytestext decoded from charset (invalid UTF-8 sequences are replaced)

Supported charsets: UTF-8 (default), ISO-8859-1 (also latin1) and US-ASCII (ASCII). Other names are treated as UTF-8.

Example

Encode text as Latin-1 and show the bytes. é is the single byte e9 in Latin-1 (it would be c3 a9 in UTF-8):

yaml example: string-latin1
- route:
    id: string-latin1
    from:
      uri: direct:string-latin1
      steps:
        - marshal:
            string:
              charset: ISO-8859-1
        - marshal:
            hex: {}
text
café
text
636166e9

Decode Latin-1 bytes back into text:

yaml example: string-decode-latin1
- route:
    id: string-decode-latin1
    from:
      uri: direct:string-decode-latin1
      steps:
        - unmarshal:
            hex: {}
        - unmarshal:
            string:
              charset: ISO-8859-1
text
636166e9
text
café

Rust DSL

rust
b.from("direct:string-rust")
    .marshal(DataFormatDefinition::string().charset("ISO-8859-1"));

Options

optiondefaultdescription
charsetUTF-8UTF-8, ISO-8859-1 / latin1 or US-ASCII.

Common questions

How do I convert bytes to a string?

unmarshal: {string: {}} decodes UTF-8. convertBodyTo: {type: String} does the same.

Which charsets are supported?

UTF-8, ISO-8859-1 and US-ASCII. Apache Camel accepts any Java charset; Cameleer treats other names as UTF-8.

Found a problem?

If something on this page doesn't match what Cameleer does, or you hit a bug while building with it, please help fix it, whether you are a person or a coding agent: open an issue that describes what you saw, then fork the repository, fix it, add or update a test, run cargo test --workspace, and open a pull request. CONTRIBUTING.md explains the ground rules.

Edit this page on GitHub