cancel
Showing results for 
Search instead for 
Did you mean: 

unable to pass process payload using Rest api

ganeshr
Champ in-the-making
Champ in-the-making
I am trying to create a process instance with process payload using rest api.
Using http://localhost:8080/activiti-rest/service/process-instance able to create a process instance but task does not contain the data passed.
And In console it is showing the error as Caused by: org.activiti.engine.impl.javax.el.PropertyNotFoundException: Could not find property processPayload in class java.lang.String

Code:
   String uri = REST_URI + "/process-instance";
      PayloadRequest payloadRequest  = new PayloadRequest();
       payloadRequest.setEmpName("Test");
        payloadRequest.setEmpCode("123");
         —

          JSONStringer jsRequest = new JSONStringer();
          jsRequest.object();
          jsRequest.key("processDefinitionKey").value(processDefinitionId);
          jsRequest.key("processPayloadData").value(payloadRequest);        
          jsRequest.endObject();
          Representation rep = new JsonRepresentation(jsRequest);
          rep.setMediaType(MediaType.APPLICATION_JSON);
          JSONObject jsObj = new JSONObject(getClientResource(uri).post(rep).getText());
          System.out.println("Returning processId " + jsObj.getString("id"));

  Does Rest api does not accept Java object as variables?
3 REPLIES 3

frederikherema1
Star Contributor
Star Contributor
How does the JSON look like (what is the value of the payload-key in JSON)? This is the way variables are loaded from the JSON, and you see the default is to use the string-value:


if (valueNode.isBoolean()) {
          variables.put(name, valueNode.getBooleanValue());
        } else if (valueNode.isInt()) {
          variables.put(name, valueNode.getIntValue());
        } else if (valueNode.isLong()) {
          variables.put(name, valueNode.getLongValue());
        } else if (valueNode.isDouble()) {
          variables.put(name, valueNode.getDoubleValue());
        } else if (valueNode.isTextual()) {
          variables.put(name, valueNode.getTextValue());
        } else {
          variables.put(name, valueNode.getValueAsText());
        }

ganeshr
Champ in-the-making
Champ in-the-making
So is not possible to send a Java POJO object instead of String/Boolean/Long value as part of calling Rest api?

frederikherema1
Star Contributor
Star Contributor
No, it's not. This requires us to have a mechanism for deserializing JSON to arbitrary java-objects in activiti-rest. The rest-service is meant for communicating over HTTP, potentially using non-java frameworks. If you really want to use your own Java-objects, you can use the Java-api for this…