John S
John S

Reputation: 8349

Serialize nullable fields from an object c#

I am trying to serialize an object that has nullable fields. If the field doesn't have any data in it the field is dropped from the serialized output. Any suggests on how to work around this? Is there a way to specify that nullable empty fields still get carried over?

This occurs when "propertyname_specified = false"

Upvotes: 0

Views: 1395

Answers (2)

arbiter
arbiter

Reputation: 9605

You must apply XmlElementAttribute:

[XmlElement(IsNullable = true)]
public string DummyField { get; set; }

Upvotes: 3

clemahieu
clemahieu

Reputation: 1429

This is how nulls are communicated in .NET XML serialization, the element doesn't exist.

Upvotes: 2

Related Questions