aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/json
diff options
context:
space:
mode:
authorGodfrey Chan <godfreykfc@gmail.com>2013-11-20 09:21:38 -0800
committerGodfrey Chan <godfreykfc@gmail.com>2013-11-26 09:51:51 -0800
commitd4ef6c00298103144eeda3f5f40ead2f184afacb (patch)
tree7cbe4f38cef3c426950574d6e769f9ea01d68f08 /activesupport/lib/active_support/json
parent80e7552073712e102c584cfc54cb3eff2c1f0f52 (diff)
downloadrails-d4ef6c00298103144eeda3f5f40ead2f184afacb.tar.gz
rails-d4ef6c00298103144eeda3f5f40ead2f184afacb.tar.bz2
rails-d4ef6c00298103144eeda3f5f40ead2f184afacb.zip
Make the JSON encoder pluggable
Diffstat (limited to 'activesupport/lib/active_support/json')
-rw-r--r--activesupport/lib/active_support/json/encoding.rb10
1 files changed, 8 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/json/encoding.rb b/activesupport/lib/active_support/json/encoding.rb
index 945aaaa2cd..935dd88a03 100644
--- a/activesupport/lib/active_support/json/encoding.rb
+++ b/activesupport/lib/active_support/json/encoding.rb
@@ -5,6 +5,7 @@ module ActiveSupport
class << self
delegate :use_standard_json_time_format, :use_standard_json_time_format=,
:escape_html_entities_in_json, :escape_html_entities_in_json=,
+ :json_encoder, :json_encoder=,
:to => :'ActiveSupport::JSON::Encoding'
end
@@ -15,11 +16,11 @@ module ActiveSupport
# ActiveSupport::JSON.encode({ team: 'rails', players: '36' })
# # => "{\"team\":\"rails\",\"players\":\"36\"}"
def self.encode(value, options = nil)
- Encoding::Encoder.new(options).encode(value)
+ Encoding.json_encoder.new(options).encode(value)
end
module Encoding #:nodoc:
- class Encoder #:nodoc:
+ class JSONGemEncoder #:nodoc:
attr_reader :options
def initialize(options = nil)
@@ -108,6 +109,10 @@ module ActiveSupport
# as a safety measure.
attr_accessor :escape_html_entities_in_json
+ # Sets the encoder used by Rails to encode Ruby objects into JSON strings
+ # in +Object#to_json+ and +ActiveSupport::JSON.encode+.
+ attr_accessor :json_encoder
+
# Deprecate CircularReferenceError
def const_missing(name)
if name == :CircularReferenceError
@@ -133,6 +138,7 @@ module ActiveSupport
self.use_standard_json_time_format = true
self.escape_html_entities_in_json = true
+ self.json_encoder = JSONGemEncoder
end
end
end