javascript - 在camunda进程的进程变量中传递json
问题描述
我正在尝试将变量中的 json 有效负载作为值传递,以使用 engine-rest api 启动流程定义,如下所示:-
接口:
身体 :
{
"variables": {
"payload": {
"value": {
"mode": "email",
"meta": [{
"key": "topic",
"value": "weather"
}, {
"key": "qos",
"value": "2"
}]
},
"type": "Json"
}
}
}
但它给出了 400 BAD REQUEST 并出现以下错误:- 必须为 SerializableValue 类型“Json”的值提供“null”或字符串值。
此外,我在我的 BPMN 流程中使用了一个表达式来获取如下所示的键值对,它也给我带来了错误:-
${S(payload).prop("mode").stringValue() == 'email'}
现在工作步骤:-当我尝试以字符串格式发送正文 json 有效负载时,它工作正常。
接口:
身体:
{
"variables": {
"payload": {
"value": "{\"mode\": \"email\",\"meta\": [{\"key\": \"topic\",\"value\": \"weather\"},{\"key\": \"qos\",\"value\": \"2\"}]}",
"type": "String"
}
}
}
我在这里使用相同的 java 代码来获取 json 有效负载-
public void notify(DelegateExecution delegateProcessExecution) throws Exception {
Object notificationPayload =
delegateProcessExecution.getVariable("payload");
if (null != notificationPayload) {
String notifyPayload = notificationPayload.toString();
JSONObject inputJson = new JSONObject(notifyPayload);
}
// ...
}
所以我希望这个有效载荷作为整个过程的 json,这样我就不需要像上面的工作示例那样将它转换为字符串。
解决方案
您应该只将类型更改为“json”,例如:
{
"variables": {
"broker": {
"value": "{\"name\":\"Broker Name\"}",
"type": "json"
}
}
}
推荐阅读
- python - 如何在 python 2.7 中将 n 个字节写入二进制文件
- amazon-web-services - 在创建、删除或更改 S3 对象的标签时触发 AWS lambda
- c++ - 模板类和接口的继承
- webhooks - 如何为 Azure 数据工厂 v2 中的 Runbook 执行配置 Webhook 活动?
- python - 使用 Python 将 csv 数据加载到 posgreSQL
- python - Python中列表列表的最大值
- javascript - 如何滚动到仍未呈现的页脚图像?
- database - 一致性维度也可以是一个缓慢变化的维度吗?
- bash - 递归地将目录中的每个文件截断为 20 行
- reactjs - 如何通知 React 组件状态变化