diff --git a/RestSharp.Tests/SerializerTests.cs b/RestSharp.Tests/SerializerTests.cs index 5c33c2053..237415833 100644 --- a/RestSharp.Tests/SerializerTests.cs +++ b/RestSharp.Tests/SerializerTests.cs @@ -78,6 +78,26 @@ public void Can_serialize_simple_POCO_With_DateFormat_Specified() { Assert.Equal(expected.ToString(), doc.ToString()); } + [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()); + } + [Fact] public void Can_serialize_simple_POCO_With_Different_Root_Element() { var poco = new Person { @@ -158,6 +178,7 @@ private class Person public decimal Price { get; set; } public DateTime StartDate { get; set; } public List Items { get; set; } + public bool? IsCool {get;set;} } private class Item @@ -220,6 +241,21 @@ private XDocument GetSimplePocoXDocWithIsoDate() { return doc; } + 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; + } + private XDocument GetSimplePocoXDocWithRoot() { var doc = new XDocument(); var root = new XElement("Result"); diff --git a/RestSharp/Serializers/XmlSerializer.cs b/RestSharp/Serializers/XmlSerializer.cs index 6b0e41edf..6ceed9058 100644 --- a/RestSharp/Serializers/XmlSerializer.cs +++ b/RestSharp/Serializers/XmlSerializer.cs @@ -171,7 +171,10 @@ private string GetSerializedValue(object obj) { output = ((DateTime)obj).ToString(DateFormat); } } - // else if... if needed for other types + if (obj is bool) + { + output = obj.ToString().ToLower(); + } return output.ToString(); }