863
Views
6
Comments
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?

2024-07-05 14-16-55
Daniël Kuhlmann
 
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

UserImage.jpg
MichaelR

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

2021-03-17 02-41-05
Brian Kong

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).

2019-02-20 16-39-47
Eric Slikker

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.


2021-03-17 02-41-05
Brian Kong

Got it. Thank you, Eric.

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

2022-05-19 09-39-13
David Sousa

I'm facing the same problem as the original poster, in fact when handling a boolean or any other field type there can be cases when the field isn't provided or is undefined.

E.g. an exposed API that allows you to update a record which has an IsActive property. If the field IsActive isn't provided in the update request then it's assumed to be false.

The only option to counter this with OutSystems is by using a text field as mentioned above, which doesn't make much sense in today's programming context. 

I guess it's just a quirk of OutSystems and something that some want fixed for a really long type, as can be seen from this 2010 idea: https://www.outsystems.com/ideas/213/null-values/

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