Skip to content

Xml Serialization of bool #165

@PaulCampbell

Description

@PaulCampbell

Hey,

I think there is an issue with xml Serialization of bool. a boolean

IsCool = true

when serialized, the value becomes

True

I don't think this is valid (I'm using openrasta which won't deserialize this...) Further, I think the valid version of booleans according to xml schema are: true and false

here's a test:

    [Fact]
    public void Can_serialize_simple_POCO_With_XmlFormat_Specified()
    {
        var poco = new Person
        {
            Name = "Foo",
            Age = 50,
            Price = 19.95m,
            StartDate = new DateTime(2009, 12, 18, 10, 2, 23),
            IsCool = false
        };

        var xml = new XmlSerializer();
        xml.DateFormat = DateFormat.Iso8601;
        var doc = xml.Serialize(poco);
        var expected = GetSimplePocoXDocWithXmlProperty();

        Assert.Equal(expected.ToString(), doc.ToString());
    }

    private XDocument GetSimplePocoXDocWithXmlProperty()
    {
        var doc = new XDocument();
        var root = new XElement("Person");
        root.Add(new XElement("Name", "Foo"),
                new XElement("Age", 50),
                new XElement("Price", 19.95m),
                new XElement("StartDate", new DateTime(2009, 12, 18, 10, 2, 23).ToString("s")),
                new XElement("IsCool", false));

        doc.Add(root);

        return doc;
    }

Not sure what the policy is with fixes, but I will chuck across a pull request too...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions