I am exposing a PUT Rest API in OutSystems and the input is a structure - including multiple integer attributes. The problem I have, is that when the consumer only wants to update certain values and thus leaves off the values that shouldn't be updated, the structure interprets those blanks as 0 (when they are integers) and not as Null which means that I can't determine whether they left it off because they didn't want to update it or if they intended to update it to 0. how can I get around this?
Thanks in advance!
There are 3 options as far as i can tell.
- You can make all attributes in your structure Text and do the validation yourself. You can check if value is empty or "NULL".
- You can add an attribute for each field that would determine if the field must be updated or not.
- You can make the request plaintext instead of JSON/structure and perform full validation on the text.
I think option 1 has least impact for your situation.
Hi Nicholas,
I'd like to add option 4 :
If you would know of an integer value that falls outside of the domain of a given attribute, you can set that as the 'default value' for that attribute in the structure.
If a piece of data is not present in the json, Outsystems fills your input structure with that default value.
The default value for integers if you don't say otherwise, is 0, which is why you get the value 0 in your input attribute when it is missing in the json (see remark in yellow, the default value for integer data types is 0 ).
So, for example, if you have an integer for the age of a person in your structure, you know this can't be negative, so you can make the default value of that attribute -666, and whenever you process a PUT request, you can check for equality with -666 to know if it was left empty.
The cleanest would be to find a very large (positive or negative) (long)integer value that is very unlikely to ever be a real value for anything, and use that on all your (long)integer attributes. These are the limits to your imagination :
Dorine