Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pass json in process variables in camunda process

I am trying to pass json payload in variables as value to start a process definition using engine-rest api as below:-

API:

http://localhost:8080/engine-rest/process-definition/processService:1:9459dbe9-6b2c-11e8-b9e8-28d2447c697a/start

Body :

{
  "variables": {
      "payload": {
        "value": {
            "mode": "email",
            "meta": [{
                "key": "topic",
                "value": "weather"
            }, {
                "key": "qos",
                "value": "2"
            }]
        },
        "type": "Json"
      }
  }
}

but it is giving 400 BAD REQUEST with below error:- Must provide 'null' or String value for value of SerializableValue type 'Json'.

Also i have used a expression in my BPMN process to fetch a key-value pair like below, it also throwing me error :-

${S(payload).prop("mode").stringValue() == 'email'}

Now working steps:- when i try to send body json payload in string format then it works fine.

API:

http://localhost:8080/engine-rest/process-definition/processService:1:9459dbe9-6b2c-11e8-b9e8-28d2447c697a/start

Body:

{
  "variables": {
      "payload": {
        "value": "{\"mode\": \"email\",\"meta\": [{\"key\": \"topic\",\"value\": \"weather\"},{\"key\": \"qos\",\"value\": \"2\"}]}",
        "type": "String"
      }
  }
}

same java code i am using here to fetch json payload-

public void notify(DelegateExecution delegateProcessExecution) throws Exception {
   Object notificationPayload =
       delegateProcessExecution.getVariable("payload");

    if (null != notificationPayload) {
        String notifyPayload = notificationPayload.toString();  
        JSONObject inputJson = new JSONObject(notifyPayload);
    }
    // ...
}

So i want this payload as json for whole process so that i don't need to convert it to string as above working example.

like image 730
Prashant Bhagat Avatar asked Oct 29 '22 10:10

Prashant Bhagat


1 Answers

You should only change the type to "json", example:

{
    "variables": {
        "broker": {
            "value": "{\"name\":\"Broker Name\"}",
            "type": "json"
        }
    }
}
like image 117
Douglas Oliveira Avatar answered Nov 12 '22 18:11

Douglas Oliveira