# Passing array or hashmap to JavaDelegate

**URL:** <https://forum.flowable.org/t/passing-array-or-hashmap-to-javadelegate/5093>\
**Category:** Flowable Engine\
**Created:** [December 17, 2019, 3:37pm UTC](https://forum.flowable.org/t/passing-array-or-hashmap-to-javadelegate/5093 "2019-12-17T15:37:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![VladimirKhil](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/vladimirkhil/32/1655_2.png) [@VladimirKhil](https://forum.flowable.org/u/VladimirKhil)\
**Post date:** [December 17, 2019, 3:37pm UTC](https://forum.flowable.org/t/passing-array-or-hashmap-to-javadelegate/5093/1 "2019-12-17T15:37:26Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![VladimirKhil](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/vladimirkhil/32/1655_2.png) [@VladimirKhil](https://forum.flowable.org/u/VladimirKhil)\
**Post date:** [December 19, 2019, 9:25am UTC](https://forum.flowable.org/t/passing-array-or-hashmap-to-javadelegate/5093/2 "2019-12-19T09:25:13Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![joram](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/joram/32/26_2.png) [@joram](https://forum.flowable.org/u/joram)\
**Post date:** [December 19, 2019, 10:44pm UTC](https://forum.flowable.org/t/passing-array-or-hashmap-to-javadelegate/5093/3 "2019-12-19T22:44:34Z")

</div>

> [@VladimirKhil](#):
>
> You can repeate a field with the same name multiple times:

That’s quite an interesting way of solving it 😉  
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.
