Parsing null values in JSON
Hello everyone,
I'm creating a REST API with InterSystems Ensemble.
I already have a POST route that parses JSON content into an object defined in a class.
To parse the JSON content, I'm using the JSONStreamToObject method in the Ens.Util.JSON class
Here is how I use it:
Set tSC = ..JSONStreamToObject(%request.Content, .tObject, "MyClass", 1)
While the route works and does what it should, in theory.
I noticed that when passing empty string or null values inside the JSON content, the values do not appear at all in the object's instance.
Therefore, there is not difference between a null value and an undefined value.
For exemple, if I pass the following JSON string when calling my REST route:
{ "a": "1", "b": 2, "c": "", "d": null }
The values C and D are completely ignored. As if they were undefined:
<MyClass> <a>1</a> <b>2</b> </MyClass>
This is an issue because empty or null values are not used the same way as given values like A or B for instance.
I already tried setting
Even though, I noticed that it changed the XML parsing of the class by setting all values in the XML export to empty strings.
Did anyone ever experience a similar issue ?
Thank you,
Lucas