JSON expression as Multi Instance Collection

Hi,

I’m trying to use collection from json process variable as Multi Instance Collection property but with no luck

I have JSON variable named “approvers” and “humans” objects collection inside. Tried to use ${approvers.jsonPath(“$.humans”).elements()} as Collection property and got following error:

org.camunda.bpm.engine.ProcessEngineException: Unknown method used in expression: ${approvers.jsonPath("$.humans").elements()}. 
Cause: Cannot find method elements with 0 parameters in class org.camunda.spin.impl.json.jackson.query.JacksonJsonPathQuery	
at org.camunda.bpm.engine.impl.el.JuelExpression.getValue(JuelExpression.java:65)
	at org.camunda.bpm.engine.impl.el.JuelExpression.getValue(JuelExpression.java:51)
	at org.camunda.bpm.engine.impl.bpmn.behavior.MultiInstanceActivityBehavior.resolveNrOfInstances(MultiInstanceActivityBehavior.java:107)

Hovewer, looking to this class I see
public SpinList<SpinJsonNode> elements() method.

How to get rid of this error? Maybe something is wrong with my expression? Please suggest. I use Camunda via REST API only, no java code from my side involved.

Example object is:

{
 "humans":
 [
    {
	  "id":"8be0e80e-516c-db50-acda-2ca07f326f2",	   
	  "userId":"00a9e65e-f2f8-4e8b-92d5-66b734df4226"
	}
 ],
 "companies":
 [
   {
     "id":"8a0f2369-6092-ab49-f73f-60ae760073b5",
	 "companyId":"FA64DAFA-DC06-11E6-BC23-2C873C28EE9D"
   }
 ]
}

Would this work?
${approvers.prop("humans").elements()}

Thank you, Vikkee, SPIN syntax works as expected!
${S(approvers).prop("humans").elements()}

Still in doubt why json native syntax doesn’t, as variable clearly is JSON-typed, I can see it in cockpit.

1 Like

Can you just like this and see what happens?

${S(approvers).jsonPath("$.humans").elements()}

Here are some examples around this usage:

It does not work without the elements because Json can be both an object or a array. The collection of a multi instance needs it to be a Java collection. When you use elements() it types your Json object as a Json list and implements Java collection/list interfaces.