Being able to set the Primitive Type of a parameter in a JSON-structure when the response can hold the value null for that parameter - Mendix Forum

Being able to set the Primitive Type of a parameter in a JSON-structure when the response can hold the value null for that parameter

5

When you want to create a REST-call via a JSON structure and the according import mapping, when you copy paste a response where a certain parameter has value ‘null’, you can not set the primitive type and therefor the entities that are being created are simply missing that certain parameter.

For example, the JSON-response is:

{

    "apbNumber": "462127",

    "remark": null,

    "substitutes": false,

    "forwardOrders": false,

    "product": [

        {

            "cnk": "4280293",

            "deliverQty": 0,

            "deliverCode": "0",

            "replacingCnk": "",

            "stockCode": "90",

            "deliveryId": "",

            "deliveryDate": "",

            "deliveryTime": "",

            "remark": ""

        }

    ]

}

Notice the ‘remark’-parameter. This leads to the following structure:

Notice that the primitive type can not be detected and therefor not being able to alter. 

Once you get to your import mapping, the parameter is simply gone and forgotten:

As a developer, you can oversee this, leading to development that leads to errors that “occasionally happen”, making it hard to debug, frustrated customers …

Ideally, the Studio Pro highlights the parameter where this primitive type is unknown and allows the user to alter it technically. In this case, it should be a string that can handle the ‘null’-value. 

asked
3 answers

i guess what if we intend to exclude “remark” from mapping? What if we have many fields like that which I want excluded. Why to treat null different from string, integer… Also color coding usually is for some error. Excluding/including a field in mapping seems to be developer’s choice.

Created

Hi Henri

What you state, is indeed a solution manually performed. That’s also how I solve(d) it whenever I encounter it. However, the amount of time that has kept developers busy and customers waiting in those situations can build up. I’m not suggesting that Mendix should “automatically” fix this in some way, the technical thinking of the developer should still be there. I’m very happy with highlighting, a notification or something like that :)

Thank you for your feedback!

Kind regards,

Leander

Created

This is a good idea, but I don’t agree.

null is nothing, empty, so in my opinion the current behaviour is correct. If you want to map, you need to replace the null with an expectable/possible value in your JSON structure.

Created