mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-10-04 00:00:37 -04:00
Fix incorrect hash key rendering with Oj JSON encoder
This commit is contained in:
parent
8797434ae7
commit
1b0e9b49ef
@ -42,17 +42,17 @@ module HTTPX::Transcoder
|
||||
# rubocop:disable Style/SingleLineMethods
|
||||
if defined?(MultiJson)
|
||||
def json_load(*args); MultiJson.load(*args); end
|
||||
def json_dump(*args); MultiJson.dump(*args); end
|
||||
def json_dump(obj); MultiJson.dump(obj); end
|
||||
elsif defined?(Oj)
|
||||
def json_load(response, *args); Oj.load(response.to_s, *args); end
|
||||
def json_dump(*args); Oj.dump(*args); end
|
||||
def json_dump(obj); Oj.dump(obj, mode: :compat); end
|
||||
elsif defined?(Yajl)
|
||||
def json_load(response, *args); Yajl::Parser.new(*args).parse(response.to_s); end
|
||||
def json_dump(*args); Yajl::Encoder.encode(*args); end
|
||||
def json_dump(obj); Yajl::Encoder.encode(obj); end
|
||||
else
|
||||
require "json"
|
||||
def json_load(*args); ::JSON.parse(*args); end
|
||||
def json_dump(*args); ::JSON.dump(*args); end
|
||||
def json_dump(obj); ::JSON.dump(obj); end
|
||||
end
|
||||
# rubocop:enable Style/SingleLineMethods
|
||||
end
|
||||
|
@ -6,7 +6,7 @@ module HTTPX::Transcoder
|
||||
def self?.decode: (HTTPX::Response response) -> _Decoder
|
||||
|
||||
def self?.json_load: (string source, ?json_options) -> untyped
|
||||
def self?.json_dump: (_ToJson obj, *untyped) -> String
|
||||
def self?.json_dump: (_ToJson obj) -> String
|
||||
|
||||
class Encoder
|
||||
extend Forwardable
|
||||
|
@ -15,10 +15,15 @@ class ResponseYajlTest < Minitest::Test
|
||||
assert_raises(MultiJson::ParseError) { json_response.json }
|
||||
end
|
||||
|
||||
def test_request_encoders
|
||||
json_request = request json: { :a => "b" }
|
||||
assert json_request.body.to_s == %({"a":"b"})
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def request(verb = "GET", uri = "http://google.com")
|
||||
Request.new(verb, uri, Options.new)
|
||||
def request(verb = "GET", uri = "http://google.com", **args)
|
||||
Request.new(verb, uri, Options.new, **args)
|
||||
end
|
||||
|
||||
def response(*args)
|
@ -15,10 +15,15 @@ class ResponseOjTest < Minitest::Test
|
||||
assert_raises(Oj::ParseError) { json_response.json }
|
||||
end
|
||||
|
||||
def test_request_encoders
|
||||
json_request = request json: { :a => "b" }
|
||||
assert json_request.body.to_s == %({"a":"b"})
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def request(verb = "GET", uri = "http://google.com")
|
||||
Request.new(verb, uri, Options.new)
|
||||
def request(verb = "GET", uri = "http://google.com", **args)
|
||||
Request.new(verb, uri, Options.new, **args)
|
||||
end
|
||||
|
||||
def response(*args)
|
@ -15,10 +15,15 @@ class ResponseYajlTest < Minitest::Test
|
||||
assert_raises(Yajl::ParseError) { json_response.json }
|
||||
end
|
||||
|
||||
def test_request_encoders
|
||||
json_request = request json: { :a => "b" }
|
||||
assert json_request.body.to_s == %({"a":"b"})
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def request(verb = "GET", uri = "http://google.com")
|
||||
Request.new(verb, uri, Options.new)
|
||||
def request(verb = "GET", uri = "http://google.com", **args)
|
||||
Request.new(verb, uri, Options.new, **args)
|
||||
end
|
||||
|
||||
def response(*args)
|
Loading…
x
Reference in New Issue
Block a user