Export Mapping with JSON Structure containing Strings/Nulls - Mapping does not align with underlying schema

0
I am working on integrating a medical screening api into Mendix. In the example JSON they provide for their request body, the attribute AnswerData either comes through as a String (that our application would handle seperately with some funky logic), or a null value. Here’s an example. "Questions": [ { "QuestionNumber": 2, "QuestionType": 1, "AnswerData": null, "IsActive": false, "Options": [], "Answers": [], "Warning": "", "InfoMessage": null, "IsFirstWarning": false, "Id": 255, "Name": "Do you take pain relief daily for this condition?" }, { "QuestionNumber": 8, "QuestionType": 3, "AnswerData": "{\"BMIvalue\":\"\",\"Height1\":\"5\",\"Height2\":\"6\",\"IsMetric\":false,\"Weight1\": 130,\"Weight2\":\"0\"}", "IsActive": false, "Options": [], "Answers": [], "Warning": "", "InfoMessage": null, "IsFirstWarning": false, "Id": 36016, "Name": "BMI Calculator" } ] I have created my JSON structure. Created an Export Mapping, with all attributes selected and mapped automatically. Now the AnswerData attribute returns this error from the mapping   I have followed the prompt to rightclick and resolve – it does nothing.  How can I make Mendix happy with accepting nulls or strings in export mapping? Cheers all
asked
2 answers
1

In your JSON structure, you must provide all the possible fields that your object can contain:

"Questions": [
                        
                        {
                            "QuestionNumber": 8,
                            "QuestionType": 3,
                            "AnswerData": "{\"BMIvalue\":\"\",\"Height1\":\"5\",\"Height2\":\"6\",\"IsMetric\":false,\"Weight1\": 130,\"Weight2\":\"0\"}",
                            "IsActive": false,
                            "Options": [],
                            "Answers": [],
                            "Warning": "",
                            "InfoMessage": "",
                            "IsFirstWarning": false,
                            "Id": 36016,
                            "Name": "BMI Calculator"
                        }
                    ]

 

By default, Mendix use the 1st example of what your array will contain. So it took the one without the specification for the field AnswerData.

That’s why this field comes up with the type “unknown”, even if it appears in the 2nd object of the array.

 

Then, in your export mapping, the field will be empty or not, depending on what will be filled in, no issue.

answered
2

Try changing AnswerData to a simple string value. Then make sure it is nillable. That should do the trick

answered