aboutsummaryrefslogtreecommitdiffstats
path: root/activeresource/lib/active_resource/base.rb
diff options
context:
space:
mode:
authorSantiago Pastorino <santiago@wyeworks.com>2010-04-05 17:11:59 -0300
committerSantiago Pastorino <santiago@wyeworks.com>2010-04-05 17:47:02 -0300
commit72f89b5d971b48a133c4c0af56fbeda35d738dae (patch)
tree80db44253bcbdebacc3a7782808b0c1cb181b701 /activeresource/lib/active_resource/base.rb
parentc6746ffaf4a2aeb5e4cec10c2a413f5614a6d137 (diff)
downloadrails-72f89b5d971b48a133c4c0af56fbeda35d738dae.tar.gz
rails-72f89b5d971b48a133c4c0af56fbeda35d738dae.tar.bz2
rails-72f89b5d971b48a133c4c0af56fbeda35d738dae.zip
create option to include_root_in_json for ActiveResource [#2584 state:committed]
Diffstat (limited to 'activeresource/lib/active_resource/base.rb')
-rw-r--r--activeresource/lib/active_resource/base.rb9
1 files changed, 9 insertions, 0 deletions
diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb
index 5cfe4f7c7d..1e81fc099c 100644
--- a/activeresource/lib/active_resource/base.rb
+++ b/activeresource/lib/active_resource/base.rb
@@ -251,6 +251,9 @@ module ActiveResource
# The logger for diagnosing and tracing Active Resource calls.
cattr_accessor :logger
+ # Controls the top-level behavior of JSON serialization
+ cattr_accessor :include_root_in_json, :instance_writer => false
+
class << self
# Creates a schema for this resource - setting the attributes that are
# known prior to fetching an instance from the remote system.
@@ -1240,6 +1243,12 @@ module ActiveResource
case self.class.format
when ActiveResource::Formats::XmlFormat
self.class.format.encode(attributes, {:root => self.class.element_name}.merge(options))
+ when ActiveResource::Formats::JsonFormat
+ if ActiveResource::Base.include_root_in_json
+ self.class.format.encode({self.class.element_name => attributes}, options)
+ else
+ self.class.format.encode(attributes, options)
+ end
else
self.class.format.encode(attributes, options)
end