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

Remove implicit null skip from Hash to JSON serialization #7053

Merged
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions spec/std/json/serialization_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ describe "JSON serialization" do
Hash(String, Int32).from_json(%({"foo": 1, "bar": 2})).should eq({"foo" => 1, "bar" => 2})
end

it "does Hash(String, Int32)#from_json and skips null" do
Hash(String, Int32).from_json(%({"foo": 1, "bar": 2, "baz": null})).should eq({"foo" => 1, "bar" => 2})
it "raises an error Hash(String, Int32)#from_json with null value" do
expect_raises(JSON::ParseException, "Expected int but was null") do
Hash(String, Int32).from_json(%({"foo": 1, "bar": 2, "baz": null}))
end
end

it "does for Array(Int32) from IO" do
Expand Down
6 changes: 1 addition & 5 deletions src/json/from_json.cr
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,7 @@ end
def Hash.new(pull : JSON::PullParser)
hash = new
pull.read_object do |key|
if pull.kind == :null
pull.read_next
else
hash[key] = V.new(pull)
end
hash[key] = V.new(pull)
end
hash
end
Expand Down