mirror of
https://github.com/sinatra/sinatra
synced 2023-03-27 23:18:01 -04:00
choose a better default json_encoder if available
This commit is contained in:
parent
923e8080af
commit
9f3aeeeb99
2 changed files with 8 additions and 1 deletions
|
@ -64,7 +64,13 @@ module Sinatra
|
|||
end
|
||||
end
|
||||
|
||||
Base.set :json_encoder, Sinatra::JSON
|
||||
Base.set :json_encoder do
|
||||
return Yajl::Encoder if defined? Yajl::Encoder
|
||||
return JSON if defined? JSON
|
||||
return :to_json if {}.respond_to? :to_json and [].respond_to? :to_json
|
||||
Sinatra::JSON
|
||||
end
|
||||
|
||||
Base.set :json_content_type, :json
|
||||
helpers JSON
|
||||
end
|
||||
|
|
|
@ -111,4 +111,5 @@ describe Sinatra::JSON do
|
|||
describe('JSON') { it_should_behave_like "a json encoder", "json", "::JSON" }
|
||||
describe('OkJson') { it_should_behave_like "a json encoder", nil, "OkJson" }
|
||||
describe('to_json') { it_should_behave_like "a json encoder", "json", ":to_json" }
|
||||
describe('without') { it_should_behave_like "a json encoder", nil, "Sinatra::JSON" }
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue