How can I get null booleans into an outgoing payload?
Question

I'm (unfortunately) somewhat experienced with outsystems's painful lack of null support but I can't figure out what the workaround for booleans needs to be.

I'm trying to create a JSON string to feed into an extension and send to an external service.

Say my payload has two fields; If I want to not send either of these, I can select the 'Don't serialise null values" option on the OS deserializer. If I want to set both to false, that's great, I can set them both to false

The problem: If I want to set one to False and one to Null, I can't. 

If I have a payload where both False and Null are both valid values that can appear in different fields at the same time, how can I differentiate between the fields?

mvp_badge
MVP

Hi,

You could use a string instead of boolean and set it to "False", "True" or "" where the empty string represents your null value.

Alternatively you need for every Boolean an extra Boolean like <attribute>IsSpecified which you set to false if the attribute value false means null. Else you set it to true meaning that the attribute value false means false.

Regards,

Daniel

Alright, thanks Daniel. I had considered both those options and was hoping there was some other solution that I hadn't thought of which was a little less... well, awful, but I guess this is the reality of working in Outsystems.

From my thinking so far, each of these 'solutions' brings a whole pile of other issues with them.

I'll have to keep digging with the team and see what we can do to make this work

This is not an answer but the same issue I faced so I want to up-vote this question. Has anyone solved this problem without extra Boolean variable, or without different types (such as text) to replace the Boolean variable in a service? The problem is the data could be 'null' or 'empty' is representing 'false' so I cannot directly use it in SQL query (I do not want to filter an attribute, if it is null or empty).

In my opinion a Boolean only has two values and doesn't have a null option. If a NULL option is needed, the field isn't of the type boolean. 

The light is on or off.

Swagger has the same opinion: https://swagger.io/docs/specification/data-models/data-types/#boolean
type: boolean represents two values: true and false. Note that truthy and falsy values such as "true", "", 0 or null are not considered boolean values. 

If you want to - or have to - work with Null-booleans it can be solved the way Daniël describes, where the string-option has my preference.

 I guess this is the reality of working in Outsystems or any other proper tool.


Got it. Thank you, Eric.

I would use string-option to handle this one. :)

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.