|
Revision 7519, 405 bytes
(checked in by david, 3 years ago)
|
Added ActiveRecord::Base#to_json/from_json (currently does not support :include like to_xml) [DHH]. Added ActiveRecord::Base#from_xml [DHH]
|
| Line | |
|---|
| 1 |
module ActiveRecord |
|---|
| 2 |
module Serialization |
|---|
| 3 |
def to_json(options = {}, &block) |
|---|
| 4 |
JsonSerializer.new(self, options).to_s |
|---|
| 5 |
end |
|---|
| 6 |
|
|---|
| 7 |
def from_json(json) |
|---|
| 8 |
self.attributes = ActiveSupport::JSON.decode(json) |
|---|
| 9 |
self |
|---|
| 10 |
end |
|---|
| 11 |
|
|---|
| 12 |
class JsonSerializer < ActiveRecord::Serialization::Serializer |
|---|
| 13 |
def serialize |
|---|
| 14 |
serializable_record.to_json |
|---|
| 15 |
end |
|---|
| 16 |
end |
|---|
| 17 |
end |
|---|
| 18 |
end |
|---|