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

How to serialize nulls in arrays? #44

Open
JohanLarsson opened this issue Sep 13, 2018 · 4 comments
Open

How to serialize nulls in arrays? #44

JohanLarsson opened this issue Sep 13, 2018 · 4 comments

Comments

@JohanLarsson
Copy link
Member

JohanLarsson commented Sep 13, 2018

[Test]
public void ArrayOfStringWithNull()
{
    var value = new object[] { "abc", null, "cde" };
    var actual = Xml.Serialize(value);
    var expected = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + Environment.NewLine +
                   "<ArrayOfString>" + Environment.NewLine +
                   "  <String>abc</String>" + Environment.NewLine +
                   "  <String />" + Environment.NewLine +
                   "  <String>cde</String>" + Environment.NewLine +
                   "</ArrayOfString>";
    Assert.AreEqual(expected, actual);
}

Dunno if using <String /> for null and <String></String> for string.Empty is a good idea, probably not.

@JohanLarsson
Copy link
Member Author

[Test]
public void ArrayOfDifferentWithNull()
{
    var value = new object[] { "abc", null, 3 };
    var actual = Xml.Serialize(value);
    var expected = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + Environment.NewLine +
                   "<ArrayOfObject>" + Environment.NewLine +
                   "  <String>1</String>" + Environment.NewLine +
                   "  <??? />>" + Environment.NewLine +
                   "  <Int32>3</Int32>" + Environment.NewLine +
                   "</ArrayOfObject>";
    Assert.AreEqual(expected, actual);
}

@jnm2
Copy link

jnm2 commented Sep 13, 2018

<Null />?

@JohanLarsson
Copy link
Member Author

Yes it makes sense but we make the null name configurable if so

@JohanLarsson
Copy link
Member Author

https://www.w3.org/TR/xmlschema-1/#xsi_nil

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

2 participants