Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XmlNullableConverter misses DataType attribute #13

Open
Backs opened this issue Oct 11, 2022 · 0 comments
Open

XmlNullableConverter misses DataType attribute #13

Backs opened this issue Oct 11, 2022 · 0 comments

Comments

@Backs
Copy link
Contributor

Backs commented Oct 11, 2022

public class FooNullableDateTime
{
    [System.Xml.Serialization.XmlElementAttribute("DateValue", DataType = "date")]
    public Nullable<DateTime> DateValue { get; set; }
}

[Test]
public void SerializeNullableDateTime()
{
    var value = new FooNullableDateTime
    {
        DateValue = new DateTime(2011, 11, 10),
    };
    
    var serializer = GetSerializer();
    var actual = serializer.ToXml(value);
    var expected =
        @"<fooNullableDateTime xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""><DateValue>2011-11-10</DateValue></fooNullableDateTime>";

    Assert.That(actual, IsXml.Equals(expected).WithIgnoreDeclaration());
}

Result:

XML documents are Different.
  TextValue:
    Expected: 2011-11-10 at "/fooNullableDateTime/DateValue/text()" (1:87)
    Actual: 2011-11-10T00:00:00 at "/fooNullableDateTime/DateValue/text()" (1:126)

Serializer ignores DataType="date" value and serialize value as dateTime.

XmlNullableConverter contains this informaion in context:
image

But SerializeBody creates a new context with an empty XmlMember:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant