Skip to content

Commit e39a583

Browse files
committed
Merge pull request ruby-grape#169 from whiteley/silence_multijson_warnings
Silence multi_json deprecation warnings
2 parents 8ee8481 + 59e6330 commit e39a583

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

lib/grape/middleware/base.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,20 +107,20 @@ def parser_for(api_format)
107107
end
108108

109109
def decode_json(object)
110-
MultiJson.decode(object)
110+
MultiJson.load(object)
111111
end
112112

113113
def encode_json(object)
114114
return object if object.is_a?(String)
115115

116116
if object.respond_to? :serializable_hash
117-
MultiJson.encode(object.serializable_hash)
117+
MultiJson.dump(object.serializable_hash)
118118
elsif object.kind_of?(Array) && !object.map {|o| o.respond_to? :serializable_hash }.include?(false)
119-
MultiJson.encode(object.map {|o| o.serializable_hash })
119+
MultiJson.dump(object.map {|o| o.serializable_hash })
120120
elsif object.respond_to? :to_json
121121
object.to_json
122122
else
123-
MultiJson.encode(object)
123+
MultiJson.dump(object)
124124
end
125125
end
126126

lib/grape/middleware/error.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ def encode_json(message, backtrace)
2424
if (options[:rescue_options] || {})[:backtrace] && backtrace && ! backtrace.empty?
2525
result = result.merge({ :backtrace => backtrace })
2626
end
27-
MultiJson.encode(result)
27+
MultiJson.dump(result)
2828
end
2929

3030
def encode_txt(message, backtrace)
31-
result = message.is_a?(Hash) ? MultiJson.encode(message) : message
31+
result = message.is_a?(Hash) ? MultiJson.dump(message) : message
3232
if (options[:rescue_options] || {})[:backtrace] && backtrace && ! backtrace.empty?
3333
result += "\r\n "
3434
result += backtrace.join("\r\n ")

spec/grape/api_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ def hello
656656
raise "rain!"
657657
end
658658
get '/exception'
659-
json = MultiJson.decode(last_response.body)
659+
json = MultiJson.load(last_response.body)
660660
json["error"].should eql 'rain!'
661661
json["backtrace"].length.should > 0
662662
end

spec/grape/middleware/formatter_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
it 'should look at the bodies for possibly serializable data' do
1111
@body = {"abc" => "def"}
1212
status, headers, bodies = *subject.call({'PATH_INFO' => '/somewhere', 'HTTP_ACCEPT' => 'application/json'})
13-
bodies.each{|b| b.should == MultiJson.encode(@body) }
13+
bodies.each{|b| b.should == MultiJson.dump(@body) }
1414
end
1515

1616
it 'should call #to_json first if it is available' do

0 commit comments

Comments
 (0)