JSON.stringify() is a JavaScript function, and it only accepts JavaScript types. This error occurs when a Java object (likely a Java String from a messageCache.getValue()) is added as an attribute in your JavaScript object.
The short answer is to convert the values to a JavaScript type object like this:
var newMessage = {};
newMessage.firstName = "" + messageCache.getValue("firstName");
newMessage.middleName = "" + messageCache.getValue("middleName");
newMessage.lastName = "" + messageCache.getValue("lastName");
qie.info(JSON.stringify(newMessage));
By prepending the value with an empty string, it converts it to be a JavaScript string, and this will work.
After some additional research,
JSON.stringify has a "replacer" parameter which we can be use to convert Java objects into JavaScript equivilants. This can be done like this:
var replacer = function(key, value) {
var returnValue = value;
try {
if (value.getClass() !== null) { // If Java Object
// qie.debug(key + ': value.getClass() = ' + value.getClass());
if (value instanceof java.lang.Number) {
returnValue = 1 * value;
} else if (value instanceof java.lang.Boolean) {
returnValue = value.booleanValue();
} else { // if (value instanceof java.lang.String) {
returnValue = '' + value;
}
}
} catch (err) {
// No worries... not a Java object
}
return returnValue;
};
qie.info(JSON.stringify(newMessage, replacer));
I have uploaded a sample channel configuration with a more complete example: