# Start process instance with a json variable

**URL:** <https://forum.flowable.org/t/start-process-instance-with-a-json-variable/11661>\
**Category:** Flowable Engine\
**Created:** [July 26, 2024, 7:54pm UTC](https://forum.flowable.org/t/start-process-instance-with-a-json-variable/11661 "2024-07-26T19:54:29Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![deepakkapoor23](https://avatars.discourse-cdn.com/v4/letter/d/71c47a/32.png) [@deepakkapoor23](https://forum.flowable.org/u/deepakkapoor23)\
**Post date:** [July 26, 2024, 7:54pm UTC](https://forum.flowable.org/t/start-process-instance-with-a-json-variable/11661/1 "2024-07-26T19:54:29Z")

</div>

I see that the process config has JsonObjectRestVariableConverter registered, is that all it needs or an additional config is required? After the process is created, the variable named customer is being set as null but I expect a json node

Here is a sample post request to start the process instance.

```auto
curl --location 'localhost:8080/process-api/runtime/process-instances' \
--header 'Content-Type: application/json' \
--data '{
    "processDefinitionKey": "saveOrder",
    "businessKey": "dummy",
    "returnVariables": true,
    "transientVariables ": [
        {
            "name": "customer",
            "type": "json",
            "value": {
                "name": "kermit",
                "age": 30,
                "address": {
                    "city": "New York"
                }
            }
        }
    ]
}'

```

---

<div class="post-metadata">

**Author:** ![filiphr](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/filiphr/32/315_2.png) [@filiphr](https://forum.flowable.org/u/filiphr)\
**Post date:** [July 26, 2024, 10:24pm UTC](https://forum.flowable.org/t/start-process-instance-with-a-json-variable/11661/2 "2024-07-26T22:24:23Z")

</div>

> [@deepakkapoor23](#):
>
> After the process is created, the variable named customer is being set as null but I expect a json node

What do you mean the variable is set as `null`? From what I can see you are using `transientVariable`, which means that the `customer` variable is only available in the transaction, after the the transaction ends the variable will no longer be available, i.e. the variable is not stored in the database.

Cheers,  
Filip

---

<div class="post-metadata">

**Author:** ![deepakkapoor23](https://avatars.discourse-cdn.com/v4/letter/d/71c47a/32.png) [@deepakkapoor23](https://forum.flowable.org/u/deepakkapoor23)\
**Post date:** [July 27, 2024, 12:15am UTC](https://forum.flowable.org/t/start-process-instance-with-a-json-variable/11661/3 "2024-07-27T00:15:25Z")

</div>

I have tried both variables and transientVariables but it doesn’t set it in execution context. When I try to retrieve it back it’s returned as null

---

<div class="post-metadata">

**Author:** ![deepakkapoor23](https://avatars.discourse-cdn.com/v4/letter/d/71c47a/32.png) [@deepakkapoor23](https://forum.flowable.org/u/deepakkapoor23)\
**Post date:** [July 27, 2024, 2:37am UTC](https://forum.flowable.org/t/start-process-instance-with-a-json-variable/11661/4 "2024-07-27T02:37:28Z")

</div>

Looks like RestVariable inside ProcessInstanceCreateRequest for a json variable is being mapped to LinkedHashMap instead of JsonNode, thats what is causing variable to be set as null. This must be fixed.

As a workaround, I had to create a custom controller to do that conversion and then start the process using runtime service.

---

<div class="post-metadata">

**Author:** ![filiphr](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/filiphr/32/315_2.png) [@filiphr](https://forum.flowable.org/u/filiphr)\
**Post date:** [July 29, 2024, 6:43am UTC](https://forum.flowable.org/t/start-process-instance-with-a-json-variable/11661/5 "2024-07-29T06:43:12Z")

</div>

Hey @deepakkapoor23,

> [@deepakkapoor23](#):
>
> Looks like RestVariable inside ProcessInstanceCreateRequest for a json variable is being mapped to LinkedHashMap instead of JsonNode, thats what is causing variable to be set as null. This must be fixed.

This is working correctly. Have a look at the [test case](https://github.com/flowable/flowable-engine/commit/7e56bc685e929e2e0153ce99ed643c1570e9922a). If something is not working for you, then please provide a test case showing what isn’t working.

Cheers,  
Filip

---

<div class="post-metadata">

**Author:** ![deepakkapoor23](https://avatars.discourse-cdn.com/v4/letter/d/71c47a/32.png) [@deepakkapoor23](https://forum.flowable.org/u/deepakkapoor23)\
**Post date:** [July 29, 2024, 11:27am UTC](https://forum.flowable.org/t/start-process-instance-with-a-json-variable/11661/6 "2024-07-29T11:27:21Z")

</div>

ProcessInstanceResource doesn’t even have the create method I am using so I don’t know what this just is testing. I will write a test when I get a chance. It’s not high priority for me anymore since I worked around it already.

---

<div class="post-metadata">

**Author:** ![filiphr](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/filiphr/32/315_2.png) [@filiphr](https://forum.flowable.org/u/filiphr)\
**Post date:** [July 29, 2024, 1:59pm UTC](https://forum.flowable.org/t/start-process-instance-with-a-json-variable/11661/7 "2024-07-29T13:59:02Z")

</div>

> [@deepakkapoor23](#):
>
> ProcessInstanceResource doesn’t even have the create method I am using so I don’t know what this just is testing.

The test is for the `ProcessInstanceCollectionResource`, not the `ProcessInstanceResource`. Those are 2 different classes that have different endpoints. The `ProcessInstanceCollectionResource` does contain the method you are calling.

Cheers,  
Filip

---

<div class="post-metadata">

**Author:** ![deepakkapoor23](https://avatars.discourse-cdn.com/v4/letter/d/71c47a/32.png) [@deepakkapoor23](https://forum.flowable.org/u/deepakkapoor23)\
**Post date:** [July 29, 2024, 4:06pm UTC](https://forum.flowable.org/t/start-process-instance-with-a-json-variable/11661/8 "2024-07-29T16:06:09Z")

</div>

You are right, ProcessInstanceCollectionResource is the one I am hitting. But I think the problem is this:

> // When the variable is coming from the REST API it automatically gets converted to an ArrayList or  
> // LinkedHashMap. In all other cases JSON is saved as ArrayNode or ObjectNode. For consistency the  
> // variable is converted to such an object here.

Somehow its not reaching this path and not converting the Map variable to a JsonNode

> <https://github.com/flowable/flowable-engine/blob/flowable-7.0.1/modules/flowable-common-rest/src/main/java/org/flowable/common/rest/variable/JsonObjectRestVariableConverter.java#L45>

---

<div class="post-metadata">

**Author:** ![filiphr](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/filiphr/32/315_2.png) [@filiphr](https://forum.flowable.org/u/filiphr)\
**Post date:** [July 30, 2024, 5:59am UTC](https://forum.flowable.org/t/start-process-instance-with-a-json-variable/11661/9 "2024-07-30T05:59:28Z")

</div>

Hey @deepakkapoor23,

I really don’t know what more I can tell you. I’ve shown you a test where sending the exact same structure works as expected. Therefore, I would ask you to share a test case displaying the problem you are seeing, without that there is not more that we can do.

Cheers,  
Filip

---

<div class="post-metadata">

**Author:** ![deepakkapoor23](https://avatars.discourse-cdn.com/v4/letter/d/71c47a/32.png) [@deepakkapoor23](https://forum.flowable.org/u/deepakkapoor23)\
**Post date:** [July 30, 2024, 2:34pm UTC](https://forum.flowable.org/t/start-process-instance-with-a-json-variable/11661/10 "2024-07-30T14:34:38Z")

</div>

I will write a test when I get a chance…thanks for your help on this.
