Flowable transforming JSON/Serializable variables

Hi all,

I have a process where I execute an HTTP task that uses a variable as the JSON body.

I just wanted to note that I’m only using the REST API for this.

When I start my process, I submit my variables. This is the variable array:

 [{"name":"myJSONBody","value":{"first_field":"1","second_field":"2","last_field":"Hello World"}}]

As you can see, the variable is of type JSON and when I look up my variables I can see that it’s categorized as serializable:

{
    "name": "myJSONBody",
    "type": "serializable",
    "value": null,
    "valueUrl": "http://myurl/process-api/runtime/tasks/my-task-id/variables/myJSONBody/data",
    "scope": "global"
  }

Later on in the process, I use this variable for an HTTP task. The request body is like this:

{
"test_var": "${myJSONBody}"
}

Unfortunately, the JSON object from the variable myJSONBody now looks like this:

{first_field=1, second_field=2, last_field=Hello World}

Does anyone know why my JSON object gets transformed from this format:

"key": "value"

To this?

key=value

Is there any way to store my JSON object in a variable exactly as is without it being modified? If not, is there a function I can call in the HTTP Task request body that would convert this to be in the exact same format before? I’m trying to understand this behavior of why this is happening. As you can imagine, when this call is made, the body being submitted is incorrectly formatted and the API can’t understand the request body.

I tried reading some documentation from the link below, but it doesn’t go too far in depth of how serializable variables function:

https://flowable.com/open-source/docs/bpmn/ch15-REST/

Is it possible for me to have my variable be saved in the following format?

{"first_field":"1","second_field":"2","last_field":"Hello World"}

Any help would be greatly appreciated. Thank you guys in advance!

I think if your variable really was JSON, the type would be “json”, not “serializable”. Serializable is typically for Java objects, including Maps and Lists.
I think your variable definition at the start isn’t defining the type, so I think it may be defaulting to string (from memory). Can you try setting the type explicitly to json? Something like this, maybe:

[{“name”:“myJSONBody”,“type”:“json”,“value”:{“first_field”:“1”,“second_field”:“2”,“last_field”:“Hello World”}}]

1 Like

Looks like this was exactly it! I had to specify explicitly set it to JSON.

Thank you so much!

@Catalyst344 So Flowable supports “JSON” as a variable type, despite the documentation not stating it as a supported type?

@Varriount Seems that way. I haven’t attempted to use “JSON” because I didn’t know it was an option. I assumed all JSON gets treated as serializable.

Can you point to the documentation where we state it’s not supported, then we can fix it?

If you use JsonNode/ObjectNode (on the Java level), it will be stored properly (which is what REST seems to use). All current possible types are here: https://github.com/flowable/flowable-engine/tree/master/modules/flowable-variable-service/src/main/java/org/flowable/variable/service/impl/types (including JsonType).