Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Silence multi_json deprecation warnings #169

Merged
merged 1 commit into from

2 participants

@whiteley

Replace deprecated MultiJson encode/decode with dump/load

@dblock
Owner

Thanks. Merging.

@dblock dblock merged commit e39a583 into intridea:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 25, 2012
  1. Silence multi_json deprecation warnings

    Matt Whiteley authored
This page is out of date. Refresh to see the latest.
View
8 lib/grape/middleware/base.rb
@@ -107,20 +107,20 @@ def parser_for(api_format)
end
def decode_json(object)
- MultiJson.decode(object)
+ MultiJson.load(object)
end
def encode_json(object)
return object if object.is_a?(String)
if object.respond_to? :serializable_hash
- MultiJson.encode(object.serializable_hash)
+ MultiJson.dump(object.serializable_hash)
elsif object.kind_of?(Array) && !object.map {|o| o.respond_to? :serializable_hash }.include?(false)
- MultiJson.encode(object.map {|o| o.serializable_hash })
+ MultiJson.dump(object.map {|o| o.serializable_hash })
elsif object.respond_to? :to_json
object.to_json
else
- MultiJson.encode(object)
+ MultiJson.dump(object)
end
end
View
4 lib/grape/middleware/error.rb
@@ -24,11 +24,11 @@ def encode_json(message, backtrace)
if (options[:rescue_options] || {})[:backtrace] && backtrace && ! backtrace.empty?
result = result.merge({ :backtrace => backtrace })
end
- MultiJson.encode(result)
+ MultiJson.dump(result)
end
def encode_txt(message, backtrace)
- result = message.is_a?(Hash) ? MultiJson.encode(message) : message
+ result = message.is_a?(Hash) ? MultiJson.dump(message) : message
if (options[:rescue_options] || {})[:backtrace] && backtrace && ! backtrace.empty?
result += "\r\n "
result += backtrace.join("\r\n ")
View
2  spec/grape/api_spec.rb
@@ -656,7 +656,7 @@ def hello
raise "rain!"
end
get '/exception'
- json = MultiJson.decode(last_response.body)
+ json = MultiJson.load(last_response.body)
json["error"].should eql 'rain!'
json["backtrace"].length.should > 0
end
View
2  spec/grape/middleware/formatter_spec.rb
@@ -10,7 +10,7 @@
it 'should look at the bodies for possibly serializable data' do
@body = {"abc" => "def"}
status, headers, bodies = *subject.call({'PATH_INFO' => '/somewhere', 'HTTP_ACCEPT' => 'application/json'})
- bodies.each{|b| b.should == MultiJson.encode(@body) }
+ bodies.each{|b| b.should == MultiJson.dump(@body) }
end
it 'should call #to_json first if it is available' do
Something went wrong with that request. Please try again.