JSON Payload
TIBCO BusinessEvents can deserialize a JSON payload to an event and can serialize an event to JSON.
For processing the JSON payload, you must perform these tasks. Otherwise, the payload is treated as XML:
- Select the Is JSON Payload while creating a destination. See Adding a Destination to a Channel and Destination Resource Reference.
- The event mapped to the destination should have the destination URL in its default destination field.
- Regular payload validation rules apply as they would for default XML-based events, that is, if the namespace check fails, the payload is not set. Namespace for an XML element is part of its root element, while for JSON it is part of the "attributes" node under "type".
- After a JSON payload is deserialized to an event, it is used the way an XML-based event is used.
The "type" information is no longer needed when parsing the JSON payload. Previously this was required. In the output, the "type" information for the top-level elements is only printed. The attributes of the nested elements are printed if it contains an Id or extId.
When processing the JSON payload, by default all properties are converted to their respective data type. For example, if an int property is passed as a string in the payload, it is converted to an int. To disable this default behavior and enable the behaviour where all JSON properties are treated as strings, set the system property com.tibco.datamodel.untyped to true. If you set this property to true, creating an event payload with the mapper does not convert single values to a JSON array if the payload element corresponds to an array property.
XML and JSON Payload Examples
<root xmlns="www.tibco.com/be/ontology/Events/Event2">
<param1>testProp</param1>
<param2>123</param2>
<param3>true</param3>
</root>
{"root" :
{ "attributes" :
{ "type" : "www.tibco.com/be/ontology/Events/Event2" }
,
"param1" : "testProp",
"param2" : "123",
"param3" : "true"
}
}
<Address>
<street>243 Buena Vista Avenue</street>
<city>Sunnyvale</city>
<zip>94086</zip>
</Address>
{"Address" :
{ "street" : "243 Buena Vista Avenue",
"city" : "Sunnyvale",
"zip" : "94086" }
}
Payload Without Wrapping Elements
be.http.json.rootElement.ignorebe.http.json.childAttributes.ignore
To ignore the parent element and its attributes, set the be.http.json.rootElement.ignore property to true and to ignore the child concept attributes, set the be.http.json.childAttributes.ignore to
true. The default value of these properties is
false.
be.http.json.rootElement.ignore is set to true, you cannot transform event payload data by using XPath and XSLT mapper. Use other JSON catalog functions to parse and access JSON nodes manually, or write a custom function to do the same.During JSON serialization of both concepts and events, you can use the following properties:
json.serialization.attributes.excludejson.serialization.childAttributes.exclude
To exclude all the attributes, including the top-root level attributes, set the json.serialization.attributes.exclude property to true. Whereas to ignore the child attributes of any nested elements, set the json.serialization.childAttributes.exclude property to
true. However, here the attributes at the root JSON node are printed. The default value of these properties is
false.