From 3c4c6bd0df598f865f49a983b4c65c415af4bcfc Mon Sep 17 00:00:00 2001 From: rick Date: Thu, 23 Apr 2009 00:08:40 -0700 Subject: * Add pluggable JSON backends with support for the JSON gem. [rick] Example: ActiveSupport::JSON.backend = "JSONGem" All internal Rails JSON encoding is now handled by ActiveSupport::JSON.encode(). Use of #to_json is not recommended, as it may clash with other libraries that overwrite it. However, you can recover Rails specific functionality if you really want to use #to_json. gem 'json' ActiveSupport::JSON.backend = "JSONGem" class ActiveRecord::Base alias to_json rails_to_json end --- activeresource/lib/active_resource/base.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'activeresource/lib/active_resource') diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb index 6cb5beb789..2e742267ba 100644 --- a/activeresource/lib/active_resource/base.rb +++ b/activeresource/lib/active_resource/base.rb @@ -887,9 +887,12 @@ module ActiveResource # person.to_json(:except => ["first_name"]) # # => {"last_name": "Smith"} def to_json(options={}) - attributes.to_json(options) + ActiveSupport::JSON.encode(attributes, options) end + # For compatibility with ActiveSupport::JSON.encode + alias rails_to_json to_json + # Returns the serialized string representation of the resource in the configured # serialization format specified in ActiveResource::Base.format. The options # applicable depend on the configured encoding format. -- cgit v1.2.3