Mendix 6 REST mapping implementation issue with boolean values because they are always default false and therefor included.

0
Default: do not send the empty values. This does not apply to any boolean because it always either false or true, meaning it is ALWAYS included in your rest request. Some API's reject this because the booleans are not always expected. To give an example I have a service that expects me to send the definition of a list of buttons. These are different types of buttons. And for one of these expects a boolean value. So in my model I have the "arrayOfButtons" object with a 1-* association to a button object that contains all the properties for these different types of buttons. Including the boolean value.  The problem is that if I now create buttons of this entity type. They always contain the boolean property. And therefor they are included in the REST action I'm doing. Does anyone know a way to work around this issue?   Like for example if I make specializations of the buttons? Will mendix automatically detect the deepest level of specialization? Just tested this myself with the specializations that doesn't work because it will only accept one type of entity. Sending the specialization mixed with the generalized object doesn't get accepted. It will return the error: the given member name 'booleanName' has no corresponding member in this object of type for the objects that don't have the specialization. Or can I for example restructure my JSON mappings in a way that I can start using the original REST module "primitive" object?
asked
1 answers
0

You could create a domain model like the one below:

Then create two json structures like this:

 

[{name:"test"}]
[{name:"test",
boolattr:true}]

From these json structures create two export mappings:

Then create the microflow for posting the data with these 2 mappings:

For the overview of the buttonArray page you can use the generalization to display common elements and add 2 buttons for creating the different button objects (or create an intermediary page allowing the user to select what knd of button he/she wants to create)

Now the post action will allow for posting the data with or without the boolean. You could even replace the button entity with the generalization like below:

Hope this helps you in creating the solution.

answered