Skip to content

Commit

Permalink
Don't wrap nil in JSON::Any when retrieving from the db (#878)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewmcgarvey authored Aug 29, 2022
1 parent e0437e0 commit b404d04
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions spec/avram/json_column_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ describe "JSON Columns" do
SaveBlob.update!(blob, doc: nil)
blob = BlobQuery.new.first
blob.doc.should eq nil
blob.doc.class.should eq Nil
end

it "should convert scalars and save forms" do
Expand Down
4 changes: 4 additions & 0 deletions src/avram/charms/json_extensions.cr
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ struct JSON::Any
SuccessfulCast(JSON::Any).new value
end

def parse(value : Nil)
SuccessfulCast(Nil).new nil
end

def parse(value)
SuccessfulCast(JSON::Any).new JSON.parse(value.to_json)
end
Expand Down

0 comments on commit b404d04

Please sign in to comment.