Skip to content

Commit

Permalink
Merge pull request #54 from BlackEdder/null
Browse files Browse the repository at this point in the history
Fix #53: JSON_TYPE.NULL results in exception
  • Loading branch information
BlackEdder authored Nov 17, 2016
2 parents 9e5e4a6 + 314d456 commit 4ec28e7
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion source/painlessjson/painlessjson.d
Original file line number Diff line number Diff line change
Expand Up @@ -612,8 +612,20 @@ T fromJSON(T, SerializationOptions options = defaultSerializatonOptions)(in JSON
{
return T._fromJSON(json);
}
else
else
{
if (json.type == JSON_TYPE.NULL)
return T.init;
return defaultFromJSON!(T,options)(json);
}
}

unittest {
struct P
{ string name; }

auto jv = parseJSON(`{"name": null}`);
auto j = fromJSON!P(jv);
}

/// Converting common types
Expand Down

0 comments on commit 4ec28e7

Please sign in to comment.