diff options
author | José Valim <jose.valim@gmail.com> | 2011-11-23 23:18:13 +0000 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2011-11-23 23:18:15 +0000 |
commit | 8896b4fdc8a543157cdf4dfc378607ebf6c10ab0 (patch) | |
tree | 5deca0d54d2c103d0a9e6167a756d638fc25e9ec /activesupport | |
parent | 0536ea8c7855222111fad6df71d0d09b77ea4317 (diff) | |
download | rails-8896b4fdc8a543157cdf4dfc378607ebf6c10ab0.tar.gz rails-8896b4fdc8a543157cdf4dfc378607ebf6c10ab0.tar.bz2 rails-8896b4fdc8a543157cdf4dfc378607ebf6c10ab0.zip |
Implement ArraySerializer and move old serialization API to a new namespace.
The following constants were renamed:
ActiveModel::Serialization => ActiveModel::Serializable
ActiveModel::Serializers::JSON => ActiveModel::Serializable::JSON
ActiveModel::Serializers::Xml => ActiveModel::Serializable::XML
The main motivation for such a change is that `ActiveModel::Serializers::JSON`
was not actually a serializer, but a module that when included allows the target to be serializable to JSON.
With such changes, we were able to clean up the namespace to add true serializers as the ArraySerializer.
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/json/encoding.rb | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/activesupport/lib/active_support/json/encoding.rb b/activesupport/lib/active_support/json/encoding.rb index 469ae69258..b0fd3a3c0e 100644 --- a/activesupport/lib/active_support/json/encoding.rb +++ b/activesupport/lib/active_support/json/encoding.rb @@ -50,9 +50,9 @@ module ActiveSupport end # like encode, but only calls as_json, without encoding to string - def as_json(value) + def as_json(value, use_options = true) check_for_circular_references(value) do - value.as_json(options_for(value)) + use_options ? value.as_json(options_for(value)) : value.as_json end end @@ -212,7 +212,7 @@ class Array def as_json(options = nil) #:nodoc: # use encoder as a proxy to call as_json on all elements, to protect from circular references encoder = options && options[:encoder] || ActiveSupport::JSON::Encoding::Encoder.new(options) - map { |v| encoder.as_json(v) } + map { |v| encoder.as_json(v, options) } end def encode_json(encoder) #:nodoc: @@ -239,7 +239,7 @@ class Hash # use encoder as a proxy to call as_json on all values in the subset, to protect from circular references encoder = options && options[:encoder] || ActiveSupport::JSON::Encoding::Encoder.new(options) result = self.is_a?(ActiveSupport::OrderedHash) ? ActiveSupport::OrderedHash : Hash - result[subset.map { |k, v| [k.to_s, encoder.as_json(v)] }] + result[subset.map { |k, v| [k.to_s, encoder.as_json(v, options)] }] end def encode_json(encoder) |