JSON arrays to mendix list objects

0
Hi, i'm using mendix version 10.9.0. I'm doing a REST call to a program that i have locally on my pc that should respond with a list of JSON object. Notice that i wrote "should respond", because i'm using the tornato framework and it doesn't allow me to send lists of any kind, i was wondering if there was a workaronund for this too since we are here.  Anyway, here are some images to explain the situation.   Here's what my program responds, (except that it should be in "[ ]"), this is made using postman   here's how the program is structured (the important parts are under the english comments)   Here's my mendix JSON structure:   And here's the import mapping auto generated by mendix: Although, i have no idea of what that "root" entity should be. Should it be the list of "fotografia" objects? because in the REST CALL action in my microflow there is no option to return a list of "fotografia". I don't even know if that's what i want in the first place, since i just want to create as many "fotografia" objects as are the one in the response body. I think the main issue now is to correctly send a list of JSON objects to mendix, via tornado if possible. Thanks for the help
asked
2 answers
0

Hi Damiano,

 

Please check if your JSON is valid before trying to process it in Mendix. It seems not only the brackets [] are missing, but also the comma's between the objects. You can use an online validator, like jsonlint.com

 

For simplicity, I would say: skip the Root object:

  1. Select it and delete it from the import mapping.
  2. Next, open the 'Select elements' and deselect the first item(s), such that you have the occurrence 0..* as top-level, like this:

image.png

 

You then got rid of the Root object, as you don't use it. The result of the Import Mapping will then be a list of 'fotografia'.

Keep in mind that this Import Mapping is directly creating new items in your database. For single-use or PoC projects, that's fine, for production environments I would recommend to import everything first non-persistent and perform validations on these non-persistent objects before processing and storing them.

Good luck!

answered
0

Hi Johan, 

thank you for the reply-

I've got rid of that root entity and now the rest CALL returns a list of "fotografia", thank you for that advice.

Now i tried changing my code to write this in a string:

image.png

 

I tried putting it on that website you mentiond before and here's the result:

image.png

apparently the date format is invalid (i tried checking the validation after deleting the date and in that case it's valid)

However:

  1. I think that this is the only format that mendix accepts as a date and time (and i need it to be a date and time attribute)
  2. When i try launching the REST CALL mendix returns this error:

image.png

 

I'm a bit confused on why it returns this, the objects are divided by the comma.

Thanks for the help.

 

Also, could you explain a bit more on the part you said about the import mapping creating a new object?

I didn't think that there would be other valid options, but if you can illuminate me about other approaches then tell me.

Thanks again.

answered