24
Views
2
Comments
In need of a workaround/ability to skip JSON property (decimal,0) AND send all values
Question

Im not trying to get into a debate for or against null support in OS.


My scenario is we have a "Map" property that in order to use and interact with we register the 27 possible property names (all of decimal type).  We do not own the API we are calling, so there is no possibility of altering it from that end.

These are all decimal types and related to accounting so obviously 0 is a valid value here and needs to be sent - However if when performing the GET there is no value, they cant receive a 0.  This data happens to come inside a structure that contains thousands of possible values and can exist on hundreds of different structures.  We have to be able to send 0 only when we receive 0 and not send the property if it is not returned.  Using onBefore in this case would be a nightmare to manually manipulate as it would cause us to parse through all 1,000's (in some cases 10's of thousands) of properties which can also be part of lists of the same record.  So is there any way without crashing our servers on every request to be able to consider a decimal datatype coming in as having no value and thus not be returned while also sending the valid 0- As a side note, these calls are all PUT calls so if we dont send 0 it removes the property and causes enormous issues to restore.

mvp_badge
MVP
Rank: #18

Hi Andrew,

Did you try this?

Regards,

Daniel

mvp_badge
MVP
Rank: #112

Hi Andrew,

If I go by this statement of your question

We have to be able to send 0 only when we receive 0 and not send the property if it is not returned.

Then I think you can do this with some trick. You just have to make sure that the 27 attributes (of your request/ response structure) you are talking about have "SendDefaultValue" property set to "No" (which is actually set by default) and also set their default value to some thing which you never expact to come in response of your get request (weird but just a trick).

Actually what is happening with you right now is that default value of your attribute (0 by default for decimal) will not be part of your response even if you set it to 0 in your code. So to avoid this case a weird long default value can be used and whenever you assign this value to your attribute it will never be part of your request/ response.

So this can be one of the way to do it without using onbefore event.