Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Silence multi_json deprecation warnings #169

Merged
merged 1 commit into from
Apr 25, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/grape/middleware/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions lib/grape/middleware/error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 ")
Expand Down
2 changes: 1 addition & 1 deletion spec/grape/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/grape/middleware/formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down