Skip to content

Commit

Permalink
Added bool and null for as_double()
Browse files Browse the repository at this point in the history
The code doing JSON diffs can't compare as it would run the "not a double" exception, if one side has a number and other a null value.
So we fix this by returning 0 here for double value.
  • Loading branch information
MonkeybreadSoftware authored Aug 2, 2024
1 parent 3069a9e commit ab7f9af
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions include/jsoncons/basic_json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4369,6 +4369,10 @@ namespace jsoncons {
return static_cast<double>(cast<uint64_storage>().value());
case json_storage_kind::json_const_pointer:
return cast<json_const_pointer_storage>().value()->as_double();
case json_storage_kind::null_value:
return 0;
case json_storage_kind::bool_value:
return cast<bool_storage>().value();
default:
JSONCONS_THROW(json_runtime_error<std::invalid_argument>("Not a double"));
}
Expand Down

0 comments on commit ab7f9af

Please sign in to comment.