Reputation: 1421
Starting to play with ServiceStack and I'm looking for a way to exclude null properties on the Response DTO when exporting as xml. This is the sort of thing I want to omit...
<SectorCode i:nil="true"/>
I know how to do this with ordinary Xml serialization but I'm struggling to find an option/attribute that will do this in ServiceStack.
Upvotes: 1
Views: 52
Reputation: 143319
ServiceStack doesn't have it's own XML Serializer, it just uses .NET's default DataContract Serializer so you'll need to use .NET's DataContract/DataMember attributes to customize how it's serialized, e.g:
[DataContract]
public class MyClass
{
[DataMember(EmitDefaultValue = false, IsRequired = false)]
public string SectorCode { get; set; }
}
Note when you annotate your class with [DataContract]
it becomes opt-in and you'll need to annotate each public property you want serialized with [DataMember]
.
Upvotes: 1