Browse files

move the serialized AR record logic to #as_json. Leave ActiveRecord::…

…Base#to_json to use the same Object#to_json implementation, but keep it around for documentation purposes.
  • Loading branch information...
1 parent 5a0e295 commit 55501b9f6ab46d45db04a81956579402511ad092 @technoweenie technoweenie committed Aug 5, 2009
Showing with 5 additions and 3 deletions.
  1. +5 −3 activerecord/lib/active_record/serializers/json_serializer.rb
View
8 activerecord/lib/active_record/serializers/json_serializer.rb
@@ -74,13 +74,15 @@ def self.included(base)
# {"comments": [{"body": "Don't think too hard"}],
# "title": "So I was thinking"}]}
def to_json(options = {})
+ super
+ end
+
+ def as_json(options = nil) #:nodoc:
hash = Serializer.new(self, options).serializable_record
hash = { self.class.model_name.element => hash } if include_root_in_json
- ActiveSupport::JSON.encode(hash)
+ hash
end
- def as_json(options = nil) self end #:nodoc:
-
def from_json(json)
self.attributes = ActiveSupport::JSON.decode(json)
self

0 comments on commit 55501b9

Please sign in to comment.