diff options
author | Erik Michaels-Ober <sferik@gmail.com> | 2012-04-18 22:01:31 -0700 |
---|---|---|
committer | Erik Michaels-Ober <sferik@gmail.com> | 2012-04-18 22:01:34 -0700 |
commit | 5e62670131dfa1718eaf21ff8dd3371395a5f1cc (patch) | |
tree | 310a26a8be2bee71771892d6409e67ab1503ca63 /activesupport/lib/active_support/json | |
parent | e01bf0a78acbdfc4635a2bbde88f5d530350fdc5 (diff) | |
download | rails-5e62670131dfa1718eaf21ff8dd3371395a5f1cc.tar.gz rails-5e62670131dfa1718eaf21ff8dd3371395a5f1cc.tar.bz2 rails-5e62670131dfa1718eaf21ff8dd3371395a5f1cc.zip |
Use `Object#respond_to?` to determine which MultiJson API to use
Diffstat (limited to 'activesupport/lib/active_support/json')
-rw-r--r-- | activesupport/lib/active_support/json/decoding.rb | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/activesupport/lib/active_support/json/decoding.rb b/activesupport/lib/active_support/json/decoding.rb index cbeb6c0a28..f95eb7a289 100644 --- a/activesupport/lib/active_support/json/decoding.rb +++ b/activesupport/lib/active_support/json/decoding.rb @@ -9,7 +9,13 @@ module ActiveSupport module JSON class << self def decode(json, options ={}) - data = MultiJson.decode(json, options) + # Can't reliably detect whether MultiJson responds to load, since it's + # a reserved word. Use adapter as a proxy for new features. + data = if MultiJson.respond_to?(:adapter) + MultiJson.load(json, options) + else + MultiJson.decode(json, options) + end if ActiveSupport.parse_json_times convert_dates_from(data) else @@ -18,12 +24,20 @@ module ActiveSupport end def engine - MultiJson.engine + if MultiJson.respond_to?(:adapter) + MultiJson.adapter + else + MultiJson.engine + end end alias :backend :engine def engine=(name) - MultiJson.engine = name + if MultiJson.respond_to?(:use) + MultiJson.use name + else + MultiJson.engine = name + end end alias :backend= :engine= |