REST return null for a Boolean value

0
How should I handle a json response from a REST webservice which contains a Boolean attribute with a null value : for instance "sent": null I read on this forum that a null value is not allowed for a Boolean and better is to use a enum for that case, but what if you don't have control over the webservice?
asked
3 answers
0

Found what seems to be an easier way to handle this (Works in Mx 10.6.1)

 

In the import mapping, keep the nullable boolean's data type as "Boolean", but in the "Map entity..." popup of your import mapping you should "Convert using" a microflow that:

- Receives the nullableBoolean parameter

- Returns false if ToString(nullableBoolean) = '' 

- Returns the boolean itself if ToString(nullableBoolean) != ''

 

This flow can also be reused across your project if any other boolean fields coming from external service responses are nullable

image.png

image.png

answered
1

Hi Olivier,

When you open your import mapping, you can select the import entity (grey) and select a microflow to convert attributes.

Here is a similar question that Austin and myself answered. https://forum.mendix.com/link/questions/88815

Let me know if you have any further questions.

answered
1

Map with an import mapping your data to a non-persistent entity and set the sent attribute to datatype string. After that you process you non-persistent entity to you persistent entity. If your default value for the sent attribute in your persistent model is false map the empty string to false 

In this case your mapping won't fail and you have more control over the data you get in ✋

answered