Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output null instead of undefined with Json.undefined serialization #1737

Merged
merged 1 commit into from
May 16, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion data/vibe/data/json.d
Original file line number Diff line number Diff line change
Expand Up @@ -1949,6 +1949,12 @@ struct JsonStringSerializer(R, bool pretty = false)
unittest
{
assert(serializeToJsonString(double.nan) == "null");
assert(serializeToJsonString(Json()) == "null");
assert(serializeToJsonString(Json(["bar":Json("baz"),"foo":Json()])) == `{"bar":"baz"}`);

struct Foo{Json bar = Json();}
Foo f;
assert(serializeToJsonString(f) == `{"bar":null}`);
}

/**
Expand All @@ -1968,7 +1974,7 @@ void writeJsonString(R, bool pretty = false)(ref R dst, in Json json, size_t lev
@safe // if( isOutputRange!R && is(ElementEncodingType!R == char) )
{
final switch( json.type ){
case Json.Type.undefined: dst.put("undefined"); break;
case Json.Type.undefined: dst.put("null"); break;
case Json.Type.null_: dst.put("null"); break;
case Json.Type.bool_: dst.put(json.get!bool ? "true" : "false"); break;
case Json.Type.int_: formattedWrite(dst, "%d", json.get!long); break;
Expand Down