xml_serialization.rb maybe shouldn't output empty/nil for boolean values?

I noticed that to_xml on an ActiveRecord object that has a boolean attribute, but that boolean attribute is nil, will serialize out an xml entry of type boolean but without a value; it's just empty. This is even the accepted behavior that is tested with NilXmlSerializationTest's test_should_serialize_boolean.

However, the w3c's xml schema spec on datatypes has something like this:

"An instance of a datatype that is defined as boolean can have the following legal literals {true, false, 1, 0}."

So should xml_serialization.rb force all booleans to true/false instead of allowing for the empty version of the field?

If it should compute_value could just have a:

elsif type == :boolean             value == true

in there?

I don't know if we should follow the W3C data type for this. While it is a strictly correct interpretation of "boolean", it is also common practice in the object world to rely on nil as a third boolean state... that of not knowing.

I have seen lots of places where a boolean was used to represent some choice, and nil indicated that the choice had not yet been made. If it is required that a given boolean field always be either true or false, that is a validation concern.

My .02...

Ben

inkling wrote: