Empty Booleans, API REST, Json Export Mapping

Hello there, I have an issue related to boolean attributes.  I’m using a POST method in a Rest CALL that uses an export mapping based on a Json structure. One of the attributes is a boolean, on the other end, the boolean needs to be empty in some cases and as you know in Mendix we can’t have empty booleans.  How can I POST an empty on a boolean ?! Is there any solution around this problem ?  Any help is much appreciated !  
1 answers

Hi Hamza,


I've encountered this problem in an earlier project. There are two ways to get around this.


1. Don't map the attribute to a Boolean but to an string with options ‘true’ and ‘false’ and empty. This will allow you to also have the NULL option, by returning empty. You can do this is in your export mapping by creating a conversion microflow for that attribute:

If i remember correctly, most REST services accept ‘true’/’false’ in JSON as the actual true/false Boolean values, so this should work. If not, you can use option 2.

2. Alternatively, you can manually fill the body of the POST request with a JSON string where you have replaced the ‘true’/’false’ values with the actual Boolean values. To do this, you use the export mapping action to string (with the conversion from option 1) in the microflow before you do the actual POST call. You then replace the ‘true’/’false’ values in your JSON string with true and false using a ReplaceAll:


Hopefully this works for you. 



UPDATE: Related questions are https://forum.mendix.com/#/questions/11540474045290203 and https://forum.mendix.com/link/questions/89852.