Reputation:
JSON ignores any parameters with null values. So, when I create a string using JsonConverter.ExportToString these properties are missing. Also any integers with null values are replaced with -2147483648
This becomes an issue when I try to deserialize this string (I am writing my own deserializer and not using Json.Import)
What's the best way of handling this?
Upvotes: 0
Views: 2348
Reputation: 5099
I am not sure that I understand the question. JSON is just a subset of javascript and properties with null values can be represented like so:
{"property1": 1, "property2": null}
In this case, property1
is a numeric and had value 1, while property2
has value null
. I'm not sure from which library the Json.Import and JsonConverter.ExportToString calls are coming. Anyway, assigning a null value to an integer is typical "strong-typed speak". In javascript, assigning null to a numeric (no such thing as integer in js) would just make that variable stop being numeric.
So maybe you should give us more context: libraries used, language you are using the data from (apparently not javascript).
Upvotes: 4
Reputation: 10493
Could you use an empty string i.e. "" instead of null, and use a placeholder number e.g. -2147483648 to indicate a null integer value?
Upvotes: 0