Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XML Serialization to use empty array instead of NULL

I have a property

 [XmlElement]
 public string[] Emails { get; set; }

which is initialized as string[0] at constructor.

If I XML serialize and deserialize a default instance of this object, the property is NULL.

How can I tell the XML Serializer to use an empty array instead of NULL for this property?

like image 691
Herman Schoenfeld Avatar asked Jul 15 '13 14:07

Herman Schoenfeld


1 Answers

5 years later... :) Replacing Array with List<> did the trick for me.

[XmlElement (IsNullable = false)]
public List<string> Emails {get;set;}
like image 148
dba Avatar answered Sep 20 '22 01:09

dba