Skip to content

qie.createJSONMessage

Signature: qie.createJSONMessage(template*, encoding*)

Returns: JSON Message message - the newly created message object

Replace the current message with an empty JSON-formatted message.

Note

The template can be either a 'String' or JSON. JSON can be represented by JavaScript objects, arrays and native maps and Java maps, collections, raw arrays or anything that implements the org.mozilla.javascript.Scriptable interface.

Note

The return value MUST ALWAYS be assigned to the bound-in message object.

Parameters

Type Name Description Default
String or JSON template* (optional) the JSON object template null
String encoding* (optional) the character encoding for this message Source Node encoding

Example

var jsonTemplate = `
{
    "name": "Nate",
    "age": 30,
    "isStudent": false,
    "address": {
        "street": "123 Main St",
        "city": "Somewhere",
        "zipcode": "12345"
    },
    "hobbies": ["reading", "coding", "hiking"]
}
`;
message = qie.createJSONMessage(jsonTemplate);

// create message with native JSON
message = qie.createJSONMessage({test: "test1", id: 1});

// create message with NativeMap using JSON.stringify()
var myMap = new Map();
myMap.set("test", "test5");
myMap.set("id", 5);
message = qie.createJSONMessage(JSON.stringify(Object.fromEntries(myMap)));

// create message with NativeMap passed directly to createJSONMessage()
var nativeMap = new Map();
nativeMap.set("test", "test6");
nativeMap.set("id", 6);
message = qie.createJSONMessage(nativeMap);

// create message with NativeArray
var nativeArray = ["x", "y", "z"];
message = qie.createJSONMessage(nativeArray);

// create message with Java Map
var javaMap = new java.util.LinkedHashMap();
javaMap.put("test", "test7");
javaMap.put("id", 7);
message = qie.createJSONMessage(javaMap);

// create message with Java Collection
var javaList = new java.util.ArrayList();
javaList.add("p");
javaList.add("q");
javaList.add("r");
message = qie.createJSONMessage(javaList);

// create message with Java array
var javaArray = java.lang.reflect.Array.newInstance(java.lang.String, 3);
javaArray[0] = 'foo';
javaArray[1] = 'bar';
javaArray[2] = 'baz';
message = qie.createJSONMessage(javaArray);