Skip to content

Commit 360032d

Browse files
authored
Add Path.from_json_object_key (#15877)
1 parent cefe508 commit 360032d

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

spec/std/json/serialization_spec.cr

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ describe "JSON serialization" do
3737
Path.from_json(%("foo/bar")).should eq(Path.new("foo/bar"))
3838
end
3939

40+
it "does Path.from_json_object_key" do
41+
Hash(Path, String).from_json(%({"foo/bar": "baz"})).should eq({Path.new("foo/bar") => "baz"})
42+
end
43+
4044
{% for int in BUILTIN_INTEGER_TYPES %}
4145
it "does {{ int }}.from_json" do
4246
{{ int }}.from_json("0").should(be_a({{ int }})).should eq(0)

src/json/from_json.cr

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ def String.from_json_object_key?(key : String) : String
199199
key
200200
end
201201

202+
def Path.from_json_object_key?(key : String) : Path
203+
new(key)
204+
end
205+
202206
def Array.new(pull : JSON::PullParser)
203207
ary = new
204208
new(pull) do |element|

0 commit comments

Comments
 (0)