Skip to content

Commit

Permalink
move the serialized AR record logic to #as_json. Leave ActiveRecord::…
Browse files Browse the repository at this point in the history
…Base#to_json to use the same Object#to_json implementation, but keep it around for documentation purposes.
  • Loading branch information
technoweenie committed Aug 5, 2009
1 parent 5a0e295 commit 55501b9
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions activerecord/lib/active_record/serializers/json_serializer.rb
Expand Up @@ -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
Expand Down

0 comments on commit 55501b9

Please sign in to comment.