libmir / asdf

JSON library
http://asdf.libmir.org
Boost Software License 1.0
20 stars 8 forks source link

Prevent Serializing Empty Arrays as Null #28

Closed andrewlalis closed 3 months ago

andrewlalis commented 3 months ago

Consider the following example:

import asdf;
struct S {
  int[] values;
}
string s = serializeToJson(S([]));
assert(s == "{\"values\": []}");

The assertion above fails because ASDF interprets an empty array as null, when a user would reasonably expect that if they provide an empty array to be serialized, that it should be represented in JSON as an empty array.

This pull request removes that check for null arrays, which is safe because dynamic arrays are not null in dRuntime, in the sense that you can iterate and get length and other properties of empty arrays.