Restmodule: post a request with just a list instead of an object

I need to address a rest webservice with a postwithresult request. The webservice expects a list only instead of an object. So instead of: {"name":[{objectitem 1},{objectitem 2}]} I has to be: [{objectitem 1},{objectitem 2}] Has anyone did this before or has a solution? Thanks!
1 answers

You can accomplish this by creating an extra java action that takes a string as the input. I've done this previously, and called it "postStringDataWithResult":

  • Create a java action
  • Set parameters to:
    • String: URL
    • String: dataString
    • Any Object: responseData

In your java action code, you just need this one line of code:

return RestConsumer.postObject(getContext(), collectionUrl, null, dataString, responseData).getMendixObject();

EDIT: This will throw compile errors, as my modified code also had adjustments to the "postObject" and "request" methods in

Here is a link to the modified files you should need, including the new java action: here.

Once you've got this set up, in your microflow, either:

  • Build the JSON string you need manually with a loop
  • Or, use the "serializeObjectToJson" java action to create a JSON string in the structure like your first code snippet above. Then manipulate that string by removing the extra outer object.

Finally, pass that into your new java action.