Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,17 @@ private void WriteElement(object? o, ElementAccessor element, bool writeAccessor
{
WriteQualifiedNameElement(name, ns!, element.Default, (XmlQualifiedName)o!, element.IsNullable, mapping.IsSoap, mapping);
}
else if (o == null && element.IsNullable)
{
if (mapping.IsSoap)
{
WriteNullTagEncoded(element.Name, ns);
}
else
{
WriteNullTagLiteral(element.Name, ns);
}
}
else
{
WritePrimitiveMethodRequirement suffixNullable = mapping.IsSoap ? WritePrimitiveMethodRequirement.Encoded : WritePrimitiveMethodRequirement.None;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@ public static void Xml_ByteArrayAsRoot()
Assert.Equal(x, y);
}

[Fact]
public static void Xml_ByteArrayNull()
{
Assert.Null(SerializeAndDeserialize<byte[]>(null,
@"<?xml version=""1.0""?>
<base64Binary d1p1:nil=""true"" xmlns:d1p1=""http://www.w3.org/2001/XMLSchema-instance"" />"));
byte[] x = new byte[] { 1, 2 };
byte[] y = SerializeAndDeserialize<byte[]>(x,
@"<?xml version=""1.0""?>
<base64Binary>AQI=</base64Binary>");
Assert.Equal(x, y);
}

[Fact]
public static void Xml_CharAsRoot()
{
Expand Down Expand Up @@ -1279,6 +1292,19 @@ public static void XML_TypeWithByteArrayAsXmlAttribute()
Assert.True(Enumerable.SequenceEqual(value.XmlAttributeForms, actual.XmlAttributeForms));
}

[Fact]
public static void XML_TypeWithNullableByteArray()
{
var value = new TypeWithNullableByteArray(); // XmlAttributeForms == null

var actual = SerializeAndDeserialize(value,
"<?xml version=\"1.0\"?>\r\n<MyXmlType xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\r\n <XmlAttributeForms xsi:nil=\"true\" />\r\n</MyXmlType>");

Assert.NotNull(actual);
Assert.Null(value.XmlAttributeForms);
Assert.Null(actual.XmlAttributeForms);
}

[Fact]
public static void XML_TypeWithByteArrayArrayAsXmlAttribute()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1987,6 +1987,13 @@ public class TypeWithByteArrayAsXmlAttribute
public byte[] XmlAttributeForms;
}

[XmlType(TypeName = "MyXmlType")]
public class TypeWithNullableByteArray
{
[XmlElement(DataType = "base64Binary", IsNullable = true)]
public byte[] XmlAttributeForms { get; set; }
}

[XmlType(TypeName = "MyXmlType")]
public class TypeWithByteArrayArrayAsXmlAttribute
{
Expand Down