aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/serializers/json_serializer.rb
blob: 8b1b8299f8078dae4ba002a48391cac2d0d21d0d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
module ActiveRecord #:nodoc:
  module Serialization
    def to_json(options = {})
      JsonSerializer.new(self, options).to_s
    end

    def from_json(json)
      self.attributes = ActiveSupport::JSON.decode(json)
      self
    end

    class JsonSerializer < ActiveRecord::Serialization::Serializer #:nodoc:
      def serialize
        serializable_record.to_json
      end
    end
  end
end