Skip to content

Commit ce4456f

Browse files
committed
Replace multi_json with json
1 parent 98ade30 commit ce4456f

File tree

4 files changed

+19
-46
lines changed

4 files changed

+19
-46
lines changed

actionpack/test/dispatch/request/json_params_parsing_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def teardown
6262
$stderr = StringIO.new # suppress the log
6363
json = "[\"person]\": {\"name\": \"David\"}}"
6464
exception = assert_raise(ActionDispatch::ParamsParser::ParseError) { post "/parse", json, {'CONTENT_TYPE' => 'application/json', 'action_dispatch.show_exceptions' => false} }
65-
assert_equal MultiJson::DecodeError, exception.original_exception.class
65+
assert_equal JSON::ParserError, exception.original_exception.class
6666
assert_equal exception.original_exception.message, exception.message
6767
ensure
6868
$stderr = STDERR

activesupport/activesupport.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
2121
s.rdoc_options.concat ['--encoding', 'UTF-8']
2222

2323
s.add_dependency('i18n', '~> 0.6', '>= 0.6.4')
24-
s.add_dependency 'multi_json', '~> 1.3'
24+
s.add_dependency 'json', '~> 1.7'
2525
s.add_dependency 'tzinfo', '~> 0.3.37'
2626
s.add_dependency 'minitest', '~> 4.2'
2727
s.add_dependency 'thread_safe','~> 0.1'

activesupport/lib/active_support/json/decoding.rb

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require 'active_support/core_ext/module/attribute_accessors'
22
require 'active_support/core_ext/module/delegation'
3-
require 'multi_json'
3+
require 'json'
44

55
module ActiveSupport
66
# Look for and parse json strings that look like ISO 8601 times.
@@ -13,32 +13,15 @@ class << self
1313
#
1414
# ActiveSupport::JSON.decode("{\"team\":\"rails\",\"players\":\"36\"}")
1515
# => {"team" => "rails", "players" => "36"}
16-
def decode(json, options ={})
17-
data = MultiJson.load(json, options)
16+
def decode(json, proc = nil, options = {})
17+
data = ::JSON.load(json, proc, options)
1818
if ActiveSupport.parse_json_times
1919
convert_dates_from(data)
2020
else
2121
data
2222
end
2323
end
2424

25-
def engine
26-
MultiJson.adapter
27-
end
28-
alias :backend :engine
29-
30-
def engine=(name)
31-
MultiJson.use(name)
32-
end
33-
alias :backend= :engine=
34-
35-
def with_backend(name)
36-
old_backend, self.backend = backend, name
37-
yield
38-
ensure
39-
self.backend = old_backend
40-
end
41-
4225
# Returns the class of the error that will be raised when there is an
4326
# error in decoding JSON. Using this method means you won't directly
4427
# depend on the ActiveSupport's JSON implementation, in case it changes
@@ -50,7 +33,7 @@ def with_backend(name)
5033
# Rails.logger.warn("Attempted to decode invalid JSON: #{some_string}")
5134
# end
5235
def parse_error
53-
MultiJson::DecodeError
36+
::JSON::ParserError
5437
end
5538

5639
private

activesupport/test/json/decoding_test.rb

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -55,35 +55,25 @@ class TestJSONDecoding < ActiveSupport::TestCase
5555
%q({"a":"Line1\u000aLine2"}) => {"a"=>"Line1\nLine2"}
5656
}
5757

58-
backends = [:ok_json]
59-
backends << :json_gem if defined?(::JSON)
60-
backends << :yajl if defined?(::Yajl)
61-
62-
backends.each do |backend|
63-
TESTS.each do |json, expected|
64-
test "json decodes #{json} with the #{backend} backend" do
65-
prev = ActiveSupport.parse_json_times
66-
ActiveSupport.parse_json_times = true
67-
silence_warnings do
68-
ActiveSupport::JSON.with_backend backend do
69-
assert_equal expected, ActiveSupport::JSON.decode(json)
70-
end
71-
end
72-
ActiveSupport.parse_json_times = prev
73-
end
74-
end
75-
76-
test "json decodes time json with time parsing disabled with the #{backend} backend" do
58+
TESTS.each do |json, expected|
59+
test "json decodes #{json}" do
7760
prev = ActiveSupport.parse_json_times
78-
ActiveSupport.parse_json_times = false
79-
expected = {"a" => "2007-01-01 01:12:34 Z"}
80-
ActiveSupport::JSON.with_backend backend do
81-
assert_equal expected, ActiveSupport::JSON.decode(%({"a": "2007-01-01 01:12:34 Z"}))
61+
ActiveSupport.parse_json_times = true
62+
silence_warnings do
63+
assert_equal expected, ActiveSupport::JSON.decode(json)
8264
end
8365
ActiveSupport.parse_json_times = prev
8466
end
8567
end
8668

69+
test "json decodes time json with time parsing disabled" do
70+
prev = ActiveSupport.parse_json_times
71+
ActiveSupport.parse_json_times = false
72+
expected = {"a" => "2007-01-01 01:12:34 Z"}
73+
assert_equal expected, ActiveSupport::JSON.decode(%({"a": "2007-01-01 01:12:34 Z"}))
74+
ActiveSupport.parse_json_times = prev
75+
end
76+
8777
def test_failed_json_decoding
8878
assert_raise(ActiveSupport::JSON.parse_error) { ActiveSupport::JSON.decode(%({: 1})) }
8979
end

0 commit comments

Comments
 (0)