This project is archived and is in readonly mode.

#1480 ✓invalid
Emmanuel Nicolau

XmlSerializer with option skip_nils

Reported by Emmanuel Nicolau | November 26th, 2008 @ 01:50 PM | in 2.x

This patch allow you to pass the :skip_nils => true option to the to_xml method, which will prevent nil columns to be present in the output (instead of the default which generates the xml element with the nil="true" attribute). This is useful when interacting with another non-rails apps, where an empty element could be marshalled as an empty string instead of nil.

Comments and changes to this ticket

  • Pratik

    Pratik August 9th, 2009 @ 02:32 AM

    • Assigned user set to “josh”
    • Tag changed from activecord, serialization, xml to activecord, patch, serialization, xml
  • josh

    josh August 10th, 2009 @ 02:10 AM

    • State changed from “new” to “invalid”

    I don't think yet another option to the to_xml hash is going solve the worlds problems. We need a more robust way to override to_xml and do your own customizations.

  • James Sanders

    James Sanders August 19th, 2009 @ 06:33 PM

    Is it unreasonable to suggest that adding options is a better interim solution than having no easy way to control the generated xml? It seems more consistent to be able to skip the nil attribute just like we can skip the type attribute. FWIW, I'm attaching patches with that behavior against 2.3 and master

  • bshand

    bshand January 27th, 2010 @ 11:52 AM

    A number of +1's (about 5) for a skip_nils or similar option are in related ticket #2049.

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Referenced by

Pages