Let MultiJson select default JSON adapter (engine), support for latest MultiJson syntax
This commit is contained in:
parent
7e6da1a619
commit
28f3dbedd0
@ -27,7 +27,6 @@ module RablRails
|
||||
@@include_json_root = true
|
||||
|
||||
mattr_reader :json_engine
|
||||
@@json_engine = :yajl
|
||||
|
||||
mattr_accessor :use_custom_responder
|
||||
@@use_custom_responder = false
|
||||
@ -42,7 +41,7 @@ module RablRails
|
||||
end
|
||||
|
||||
def self.json_engine=(name)
|
||||
MultiJson.engine = name
|
||||
MultiJson.respond_to?(:use) ? MultiJson.use(name) : MultiJson.engine = name
|
||||
@@json_engine = name
|
||||
rescue LoadError
|
||||
Rails.logger.warn %Q(WARNING: rabl-rails could not load "#{self.json_engine}" as JSON engine, fallback to default)
|
||||
@ -53,6 +52,6 @@ module RablRails
|
||||
end
|
||||
|
||||
def self.load_default_engines!
|
||||
self.json_engine = :yajl
|
||||
self.json_engine = MultiJson.respond_to?(default_adapter) ? MultiJson.default_adapter : MultiJson.default_engine
|
||||
end
|
||||
end
|
||||
|
@ -3,7 +3,7 @@ module RablRails
|
||||
class JSON < Base
|
||||
def format_output(hash)
|
||||
hash = { _options[:root_name] => hash } if _options[:root_name] && RablRails.include_json_root
|
||||
MultiJson.encode(hash)
|
||||
MultiJson.respond_to?(:dump) ? MultiJson.dump(hash) : MultiJson.encode(hash)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user