Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

WSO2 EI provides support for JavaScript Object Notation (JSON) payloads in messages. The following sections describe how to work with JSON in the EI:

...

If you want to convert the JSON representation to XML before the mediation flow begins, you need to add the message builder and formatter shown below. Note that some data loss can occur during the JSON to XML to JSON conversion process.

  • <parameter name="passthruJsonBuilder">org.apache.synapse.commons.json.JsonBuilder</parameter>

  • <parameter name="passthruJsonFormatter">org.apache.synapse.commons.json.JsonFormatter</parameter>

The following builders and formatters can be enabled for JSON mapping in data services.

  • <parameter name="dsJsonBuilder">org.apache.axis2.json.gson.JsonBuilder</parameter>
  • <parameter name="dsJsonFormatter">org.apache.axis2.json.JSONMessageFormatter</parameter>

The following builders and formatters can also enabled. Note that this is necessary for compatibility with previous versions of the EI (WSO2 ESB):

...

Note the addition of xml-multiple processing instructions to the XML payloads whose JSON representations contain arrays. JsonBuilder (via StAXON) adds these instructions to the XML payload that it builds during the JSON to XML conversion so that during the XML to JSON conversion, JsonFormatter can reconstruct the arrays that are present in the original JSON payload. JsonFormatter interprets the elements immediately following a processing instruction to construct an arraya processing instruction to construct an array.

Info

Set the value of the synapse.json.to.xml.processing.instruction.enabled property to true in the <EI_Home>/conf/synapse.properties file, to enable adding processing instructions when performing JSON to XML conversions. For example, you can add processing instructions to identify array elements in JSON payloads with array indices (i.e., marked with "[ ]") and process them to XML.

Note

This property is available for WSO2 EI 6.1.0 via the WUM update 1716 released on the 10th of November 2017.

Special characters

When building XML elements, the EI handles the ‘$’ character and digits in a special manner when they appear as the first character of a JSON key. Following are examples of two such occurrences. Note the addition of the _JsonReader_PS_ and _JsonReader_PD_ prefixes in place of the ‘$’ and digit characters, respectively.

...

Parameter

Description

Default Value

synapse.commons.json.preserve.namespace

Preserves the namespace declarations in the JSON output in XML to JSON transformations.

false

synapse.commons.json.buildValidNCNames

Builds valid XML NCNames when building XML element names in XML to JSON transformations.

false

synapse.commons.json.output.autoPrimitive

Allows primitive types in the JSON output in XML to JSON transformations.

true

synapse.commons.json.output.namespaceSepChar

The namespace prefix separation character for the JSON output in XML to JSON transformations.

The default separation character is -

synapse.commons.json.output.enableNSDeclarations

Adds XML namespace declarations in the JSON output in XML to JSON transformations.

false

synapse.commons.json.output.disableAutoPrimitive.regex

Disables auto primitive conversion in XML to JSON transformations.

null

synapse.commons.json.output.jsonoutAutoArray

Sets the JSON output to an array element in XML to JSON transformations.

true

synapse.commons.json.output.jsonoutMultiplePI

Sets the JSON output to an xml multiple processing instruction in XML to JSON transformations.

true

synapse.commons.json.output.xmloutAutoArray

Sets the XML output to an array element in XML to JSON transformations.

true

synapse.commons.json.output.xmloutMultiplePI

Sets the XML output to an xml multiple processing instruction in XML to JSON transformations.

false
synapse.json.to.
commons
xml.
json
processing.
output
instruction.
emptyXmlElemToEmptyStr

Sets an empty element to an empty JSON string in XML to JSON transformations.

true
enabled

Enables adding processing instructions when performing JSON to XML conversions. For example, you can add processing instructions to identify array elements in JSON payloads with array indices (i.e., marked with "[ ]") and process them to XML.

Info

This property is available for WSO2 EI 6.1.0 via the WUM update 1716 released on the 10th of November 2017.



Anchor
troubleshooting
troubleshooting

...

Tip

When adding this sample schema file to the Registry, specify the Media Type as application/json.

Code Block
languagejava
{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "getQuote": {
      "type": "object",
      "properties": {
        "request": {
          "type": "object",
          "properties": {
            "symbol": {
              "type": "string"
            }
          },
          "required": [
            "symbol"
          ]
        }
      },
      "required": [
        "request"
      ]
    }
  },
  "required": [
    "getQuote"
  ]
}
 

...