Save JSON-Array to App variable and assign value of variable (type object) to $value-defintion

Hi dear AppBuilders,

my goal is to assign a JSON-Response body (from an OD function) to the $value-defintion of the config.download.excel.additionalSheets.data-Property of a data table (see Pic.1). I’ve created a variable of type object and stored an example JSON-Array as default value (see Pic. 2). I’ve tried to test the functionality by assigning this default value to the $data/value-Property, however it throws the error “Cannot deserialize value of type java.util.ArrayList<java.util.Map<java.lang.String,java.lang.Object>> from String value (token JsonToken.VALUE_STRING)” (see Pic. 3). The error makes sense and I understand why it doesn’t work, however I don’t know if there is a solution to this problem?


Screenshot 2022-09-05 142432
Screenshot 2022-09-05 141925

Any help is greatly appreciated!

I don’t know if you have already tried it, if not: try to use the “object” type for your variable:
"$data": {"type":"object", "value":"{{test_var_obj}}"} and also you may try to express the type in variable definition as well.

Heyho!

I unfortunatelly have no solution for the issue but maybe an idea worth a try.
Due to the nature of the error message, it almost certainly stems from a server-side application. This is most probably onedata-server itself (it might also be apps-server but I’m quite sure, it does not act as a broker here). Have you tried to execute the function from onedata core (Functions section) directly? Do you get the same error?
The fact that the server does not know how to deserialize the content tells me that you are quite probably using non-primitive (actually, rather binary) data types.
What should the content (when serialized to JSON) look like? If you’re dealing with binary data, base64 encoding it might be an option to forward it as JSON. However, this then bears the question of deserialization on Apps side.

Bottomline: Java server does not understand the response of your function. There is most probably nothing you can do against this on App-code level.

So I’ve found a solution:
The process goes as follows: Trigger Execute Button in App → starts OD function and create the JSON you want to use in your App; return the JSON in the Response-Body of your function → Update an app variable with the function response → use the updated variable (holding the json) in your App

The prerequsits are:

  1. Define a variable in your App with type “object” (this is important). This variable will hold the JSON from your function response.
    define_variable

  2. Define an execute button which will trigger the OD function. Add your in 1.) created variable to the variablesToBeUpdated - property. Important: Do not specify any value! (-> see Pic.2) This will allow you to access the complete JSON-response from your function in this variable.
    variables_to_be_updated

  3. When you want to access your JSON you can do so via a simple Json path expression using your variable. Important: Add “object” as your type attribute!