Payload Types

A payload is the data a message carries. Each processor in an integration flow receives a payload and passes its output to the next processor. The payload can be a JSON-compliant object or list, a string, or binary data.

Processors can convert incoming payloads automatically, but the conversion depends on the processor. You do not need to configure every conversion between processors. Add an inboundTransformationStrategy sub-builder to the receiving processor when its default handling does not produce the representation your flow needs. The strategy converts only the processor’s input, before the processor works with it. See Payload Conversions for configuration and the processor reference for each processor’s requirements. For existing property-based strategies, see Conversion by Properties (Deprecated).

JSON-compliant

A JSON-compliant payload is an in-memory object or list whose values follow JSON types: strings, numbers, booleans, null, lists, and nested objects. It gives many processors and mapping expressions a common representation of structured data, so they can read, map, and pass on its fields without parsing or serializing JSON text between steps. Convert to or from another format only where the flow needs it, for example, to read XML or to write Avro binary for an outbound processor. Some processors work directly with strings or binary data and do not need a JSON-compliant payload.

JSON text represents data in JSON syntax, held as a string or encoded as bytes. For example:

{"meterId":"M-42","reading":12.5}

In this representation, the fields are part of serialized text that must be parsed before they can be accessed.

A JSON-compliant payload already holds the same data as a structured object: a meterId field containing "M-42" and a numeric reading field containing 12.5. Processors and mapping expressions can access those fields directly.

For example, dbStatement can read named SQL parameters from a JSON-compliant object. If the payload that reaches dbStatement is JSON text, add this sub-builder to dbStatement:

inboundTransformationStrategy {
    fromJsonText().toJsonCompliant()
}

The processor also produces JSON-compliant query results; the strategy above only converts its input.

XML-compliant

The flow-server can also represent XML data as a JSON-compliant object. To preserve the XML declaration, namespaces, attributes, and text, the object must follow the XML-compliant formatting rules shown below. These rules make it possible to convert the object back to XML.

For example, a soapApi processor for SOAP endpoints might receive the following XML input:

<SayHi xmlns="http://www.bccs.uib.no/EchoService.wsdl" xmlns:aa="http://www.bccs-aa.uib.no/EchoService.wsdl">
    <Hi>hi, it's john</Hi>
    <Hi from="jane">hello</Hi>
    <aa:Hi>
        <aa:Greeting>well, hi</aa:Greeting>
        <aa:Speaker>janice</aa:Speaker>
    </aa:Hi>
    <Message xmlns="http://www.bccs-bb.uib.no/EchoService.wsdl">
        <![CDATA[
            Dear Jim,

            What's up?
        ]]>
    </Message>
</SayHi>

The flow-server converts the data to the following JSON-compliant object for the next processor to use:

{
  "_declaration": {
    "version": "1.0",
    "standalone": "no"
  },
  "ns1_SayHi": {
    "ns1_Hi": [
      {
        "_text": "hi, it's john"
      },
      {
        "_attributes": {
          "from": "jane"
        },
        "_text": "hello"
      }
    ],
    "ns2_Hi": [
      {
        "ns2_Greeting": {
          "_text": "well, hi"
        },
        "ns2_Speaker": {
          "_text": "janice"
        }
      }
    ],
    "ns3_Message": {
      "_cdata": "\n    Dear Jim,\n\n    What's up?\n    "
    }
  },
  "_xmlns": {
    "ns1": "http://www.bccs.uib.no/EchoService.wsdl",
    "ns2": "http://www.bccs-aa.uib.no/EchoService.wsdl",
    "ns3": "http://www.bccs-bb.uib.no/EchoService.wsdl"
  }
}

This example uses three XML namespaces. The _xmlns property lists them, and each one gets an incremental ns prefix. The <SayHi> and <Hi> elements belong to the first namespace, so you access them as ns1_SayHi and ns1_Hi in the object.

The XML contains only one <aa:Hi> element, but the ns2_Hi property is still an array because the XML schema for these elements defines a maxOccurs greater than one. Without a schema, the converter assumes the following:

  • Multiple adjacent elements with the same name are an array.

  • A single element with no like siblings is a regular object.

To avoid ambiguity, use an XML schema.

The text content of an element is in a child _text property. CDATA content goes in a _cdata property instead. Elements that have attributes also get an _attributes property. The following table compares an XML element with its JSON form:

XML JSON
<Hi from="jane">hello</Hi>
"ns1_Hi": [
  {
    "_attributes": {
      "from": "jane"
    },
    "_text": "hello"
  }
]

Namespace Mapping

To replace the auto-generated ns prefixes, map each namespace to a prefix of your own. The elements of a namespace mapped to _default get no prefix. The examples below map the first two namespaces above, ns1 and ns2, to _default and aa.

On soapApi, list the mappings in its namespacePrefixMapping property:

soapApi {
    id = "soap-echo-api"
    wsdlSpecId = soapResourceKey.toResourceIdentifier()
    serviceName = "EchoService"
    portName = "EchoService"
    namespacePrefixMapping = """
        _default = http://www.bccs.uib.no/EchoService.wsdl
        aa = http://www.bccs-aa.uib.no/EchoService.wsdl
    """.trimIndent()
}

On any other processor, call namespacePrefix once for each namespace, in fromXmlText inside the processor’s inboundTransformationStrategy:

inboundTransformationStrategy {
    fromXmlText {
        schemaId = "XSD:echo-service:1"
        namespacePrefix("_default", "http://www.bccs.uib.no/EchoService.wsdl")
        namespacePrefix("aa", "http://www.bccs-aa.uib.no/EchoService.wsdl")
    }.toJsonCompliant()
}

Conversion by Format describes the inboundTransformationStrategy and the other options of fromXmlText.

Either configuration converts the XML to the following JSON-compliant object. The third namespace has no mapping, so it gets the auto-generated prefix ns1:

{
  "_declaration": {
    "version": "1.0",
    "standalone": "no"
  },
  "SayHi": {
    "Hi": [
      {
        "_text": "hi, it's john"
      },
      {
        "_attributes": {
          "from": "jane"
        },
        "_text": "hello"
      }
    ],
    "aa_Hi": [
      {
        "aa_Greeting": {
          "_text": "well, hi"
        },
        "aa_Speaker": {
          "_text": "janice"
        }
      }
    ],
    "ns1_Message": {
      "_cdata": "\n    Dear Jim,\n\n    What's up?\n    "
    }
  },
  "_xmlns": {
    "_default": "http://www.bccs.uib.no/EchoService.wsdl",
    "aa": "http://www.bccs-aa.uib.no/EchoService.wsdl",
    "ns1": "http://www.bccs-bb.uib.no/EchoService.wsdl"
  }
}

Outbound XML

Data for a soapRequest processor, or the response in a soapApi flow, must follow the same XML-compliant JSON format. The following example shows a simplified version of that format:

{
  "_xmlns": {
    "_default": "namespace_1",
    "other": "namespace_2"
  },
  "Element_Name": { // namespace_1
    "Child_Element": {
      "_text": "value"
    }
  },
  "other_Element": { // namespace_2
    "_text": "value"
  }
}

The processor then interprets the data and converts it to valid XML.

Strings

A string can contain plain text or serialized data, such as JSON or XML. For example, restRequest returns a response with content type application/json as a string, not a JSON-compliant object.

Some processors work directly with text and do not automatically convert it to a JSON-compliant payload, even when the text contains valid JSON. Whether to convert the text depends on what the flow needs to do.

Text can remain a string when the flow processes the text itself or passes it on unchanged. When the flow needs to work with the JSON structure, a JSON-compliant payload gives processors and mapping expressions direct access to its fields and provides a common representation between processing steps.

Use an inboundTransformationStrategy when a processor’s default input handling does not provide the representation you need. For JSON text, add fromJsonText().toJsonCompliant() to the strategy.

See Payload Conversions for the supported conversions.

Binary

readFiles reads a file’s contents as binary data when streamingEnabled is false. Even if the file contains JSON text, the payload is bytes, not a JSON-compliant object.

A receiving processor can convert those bytes to a JSON-compliant payload with fromJsonText().toJsonCompliant() in its inboundTransformationStrategy. See Payload Conversions for the supported conversions.

Binary Serialization

To convert Avro binary to or from a JSON-compliant payload, see Conversion by Format. The payload formats table lists the other supported formats.