Passing array or hashmap to JavaDelegate

Hello!
The Flowable can inject arbitrary variable value into JavaDelegate field via expressions.
Is there a way in inject not a single value but an array of variables values or a custom hashmap? I am trying to write something like this (not working pseudocode):
<flowable:field name="collection" expression="${Arrays.asList(var1, var2)}" />
I know that I can write custom script to solve that problem but I am trying to make my BPMN as short and declarative as possible.
Is writing a custom FlowableFunctionDelegate the best solution?
Thank you!

1 Like

I have found a solution for passing arrays to dlegate. You can repeate a field with the same name multiple times:

<flowable:field name="collection" expression="${var1}" />
<flowable:field name="collection" expression="${var2}" />
<flowable:field name="collection" expression="${var3}" />

After that you need to declare method setCollection(Expression expression) in your JavaDelegate:

public setCollection(Expression expression) {
   expressions.add(expression);
}

It will be called multiple times and you can collect the array.

So, the only problem left is passing a map to JavaDelegate. The only solution I see now is passing in an array of key-separator-value strings:

<flowable:field name="collection" expression="key1:${var1}" />
<flowable:field name="collection" expression="key2:${var2}" />
<flowable:field name="collection" expression="key3:${var3}" />

But this would not allow you to use separator character inside key name.

1 Like

That’s quite an interesting way of solving it :wink:
For a map, you’d need to parse the value in key/value (and indeed you couldn’t use the separator), though.

Probably a custom function delegate is the shortest way of writing such an expression.

1 Like