# To\_xml/to\_json and serialized columns

**URL:** <https://www.ruby-forum.com/t/to-xml-to-json-and-serialized-columns/145406>\
**Category:** Rails\
**Created:** [August 8, 2008, 9:27pm UTC](https://www.ruby-forum.com/t/to-xml-to-json-and-serialized-columns/145406 "2008-08-08T21:27:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![metrix](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/48db29/32.png) [@metrix](https://www.ruby-forum.com/u/metrix)\
**Post date:** [August 8, 2008, 9:27pm UTC](https://www.ruby-forum.com/t/to-xml-to-json-and-serialized-columns/145406/1 "2008-08-08T21:27:36Z")

</div>

The AR serializer is great, but it if you’re dealing with serailized  
columns it jams yaml into the result, or whatever you’re serializing  
columns to.

If you are serializing the AR object to\_xml/to\_json, chances are you  
want the whole object in that format,not part of it.

Is there a way to tell the AR serializer it should to pay attention to  
serialized columns, rather than simply treating them as text columns?

---

<div class="post-metadata">

**Author:** ![metrix](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/48db29/32.png) [@metrix](https://www.ruby-forum.com/u/metrix)\
**Post date:** [August 10, 2008, 1:43am UTC](https://www.ruby-forum.com/t/to-xml-to-json-and-serialized-columns/145406/2 "2008-08-10T01:43:38Z")

</div>

Sorry…I was incorrect about one thing. The Serializer is detecting  
which columns are are flagged as serialized, however it will only  
serialize them as YAML.

So say you have a Customer object, and serialized column called  
favorite\_products, which contains an array of product id’s…

You call Customer.find(1).to\_xml, or Customer.find(1).to\_json, you  
respectively get an xml or json representation of that object, however  
favorite\_products will be yaml embedded in into the xml/json…when  
more often than not you’d want that to be xml or json as well.

---

<div class="post-metadata">

**Author:** ![metrix](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/48db29/32.png) [@metrix](https://www.ruby-forum.com/u/metrix)\
**Post date:** [February 1, 2009, 3:44pm UTC](https://www.ruby-forum.com/t/to-xml-to-json-and-serialized-columns/145406/3 "2009-02-01T15:44:04Z")

</div>

Hi,

I found this old email from you.

How did you fix it?  
I have YAML serialized data and need to send it over XML.

–  
cheers,  
M.

On Aug 10 2008, 1:43 am, Brandon C. \<rails-mailing-l…@andreas-
