Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

XmlSerializer with option skip_nils

#1480

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.

Reported by Emmanuel Nicolau · November 26th, 2008 @ 01:50 PM

State: invalid
Milestone: 2.x
Assigned to: josh josh
Importance: none

Activity

  1. Pratik
    Pratik
    • Assigned user set to josh
    • Tag changed from activecord, serialization, xml to activecord, patch, serialization, xml

    August 9th, 2009 @ 02:32 AM

  2. josh
    josh
    • 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.

    August 10th, 2009 @ 02:10 AM

  3. James Sanders
    James Sanders

    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

    August 19th, 2009 @ 06:33 PM

  4. bshand
    bshand

    A number of +1's (about 5) for a skip_nils or similar option are in related ticket #2049 to_xml nil => true attribute should not appear when I skip types.

    January 27th, 2010 @ 11:52 AM