From db00ecba1d791a417df71a43a371a2faf47c4500 Mon Sep 17 00:00:00 2001 From: Serdar Dogruyol Date: Sat, 10 Mar 2018 11:05:34 +0300 Subject: [PATCH] Don't use JSON::Type, use JSON::Any instead (#435) --- spec/param_parser_spec.cr | 2 +- spec/route_handler_spec.cr | 1 - src/kemal/param_parser.cr | 4 ++-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/spec/param_parser_spec.cr b/spec/param_parser_spec.cr index 4c1992f..f41325b 100644 --- a/spec/param_parser_spec.cr +++ b/spec/param_parser_spec.cr @@ -174,7 +174,7 @@ describe "ParamParser" do body_params.to_s.should eq("") json_params = Kemal::ParamParser.new(request).json - json_params.should eq({} of String => Nil | String | Int64 | Float64 | Bool | Hash(String, JSON::Type) | Array(JSON::Type)) + json_params.should eq({} of String => Nil | String | Int64 | Float64 | Bool | Hash(String, JSON::Any) | Array(JSON::Any)) end end diff --git a/spec/route_handler_spec.cr b/spec/route_handler_spec.cr index f1a53bb..8570ba7 100644 --- a/spec/route_handler_spec.cr +++ b/spec/route_handler_spec.cr @@ -85,7 +85,6 @@ describe "Kemal::RouteHandler" do post "/" do |env| skills = env.params.json["skills"].as(Array) skills_from_languages = skills.map do |skill| - skill = skill.as(Hash) skill["language"] end "Skills #{skills_from_languages.each.join(',')}" diff --git a/src/kemal/param_parser.cr b/src/kemal/param_parser.cr index e42a87a..188eb4f 100644 --- a/src/kemal/param_parser.cr +++ b/src/kemal/param_parser.cr @@ -8,7 +8,7 @@ module Kemal MULTIPART_FORM = "multipart/form-data" PARTS = %w(url query body json) # :nodoc: - alias AllParamTypes = Nil | String | Int64 | Float64 | Bool | Hash(String, JSON::Type) | Array(JSON::Type) + alias AllParamTypes = Nil | String | Int64 | Float64 | Bool | Hash(String, JSON::Any) | Array(JSON::Any) getter files def initialize(@request : HTTP::Request) @@ -89,7 +89,7 @@ module Kemal case json = JSON.parse(body).raw when Hash json.each do |key, value| - @json[key] = value.as(AllParamTypes) + @json[key] = value.raw end when Array @json["_json"] = json