Skip to content

Commit

Permalink
Added XML serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
bkeepers committed Sep 26, 2010
1 parent 16f842f commit 28c1d67
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/mongo_mapper/plugins/serialization.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# encoding: UTF-8
require 'active_model/serializers/json'
require 'active_model/serializers/xml'

module MongoMapper
module Plugins
module Serialization
def self.configure(model)
model.class_eval do
include ::ActiveModel::Serializers::JSON
include ::ActiveModel::Serializers::Xml
self.include_root_in_json = false
end
end
Expand All @@ -27,6 +29,10 @@ module ClassMethods
def from_json(json)
self.new.from_json(json)
end

def from_xml(xml)
self.new.from_xml(xml)
end
end

end
Expand Down
2 changes: 1 addition & 1 deletion test/unit/test_serialization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def setup
)
end

[:json].each do |format|
[:json, :xml].each do |format|
context format do
should "be reversable" do
serialized = @instance.send("to_#{format}")
Expand Down

0 comments on commit 28c1d67

Please sign in to comment.