Skip to content

Commit 4ec28e7

Browse files
authored
Merge pull request #54 from BlackEdder/null
Fix #53: JSON_TYPE.NULL results in exception
2 parents 9e5e4a6 + 314d456 commit 4ec28e7

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

source/painlessjson/painlessjson.d

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,8 +612,20 @@ T fromJSON(T, SerializationOptions options = defaultSerializatonOptions)(in JSON
612612
{
613613
return T._fromJSON(json);
614614
}
615-
else
615+
else
616+
{
617+
if (json.type == JSON_TYPE.NULL)
618+
return T.init;
616619
return defaultFromJSON!(T,options)(json);
620+
}
621+
}
622+
623+
unittest {
624+
struct P
625+
{ string name; }
626+
627+
auto jv = parseJSON(`{"name": null}`);
628+
auto j = fromJSON!P(jv);
617629
}
618630

619631
/// Converting common types

0 commit comments

Comments
 (0)