# From\_xml rails 2.0 no worky!

**URL:** <https://www.ruby-forum.com/t/from-xml-rails-2-0-no-worky/127548>\
**Category:** Rails\
**Created:** [January 30, 2008, 9:26am UTC](https://www.ruby-forum.com/t/from-xml-rails-2-0-no-worky/127548 "2008-01-30T09:26:13Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Corbin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58f4c7/32.png) [@Corbin](https://www.ruby-forum.com/u/Corbin)\
**Post date:** [January 30, 2008, 9:26am UTC](https://www.ruby-forum.com/t/from-xml-rails-2-0-no-worky/127548/1 "2008-01-30T09:26:13Z")

</div>

I’m trying to use my\_model.from\_xml() to rehydrate an ActiveRecord  
object with associations. When I do this I was getting either

ActiveRecord::AssociationTypeMismatch: HouseOfQuality expected, got  
Hash  
or  
ActiveRecord::AssociationTypeMismatch: HouseOfQuality expected, got  
Array

Depending on if the association I had had the type=“array” on the  
association element in the xml.

I even tried this:

bob = Bob.find(1)  
another\_bob = Person.new.from\_xml(bob.to\_xml)

Here is the what the rails 2.0 release says which I think means I  
should be able to do this…what am I doing wrong?

Active Record: XML in, JSON out

Active Record has supported serialization to XML for a while. In 2.0  
we’ve added deserialization too, so you can say  
Person.new.from\_xml(“David”) and get what you’d expect. We’ve also  
added serialization to JSON, which supports the same syntax as XML  
serialization (including nested associations). Just do person.to\_json  
and you’re ready to roll.
