Reputation: 4144
I have some JSON that can be a List or null. How do I create a POCO for this JSON?
Here is an example array: http://pastebin.com/qAZF2Ug9
Here is my POCO: http://pastebin.com/hUtgyytc
How can I tell Newtonsoft.JSON to ignore the SalesLine object, if it is null?
Upvotes: 0
Views: 1119
Reputation: 1063358
You can specify the settings:
var settings = new Newtonsoft.Json.JsonSerializerSettings {
NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore};
and use that in various serializer constructors and serialize calls.
Alternatively, IIRC it supports conditional serialization, i.e.
public bool ShouldSerializeFoo() { return Foo != null; }
// pairs to property Foo
Upvotes: 1
Reputation: 3938
Try to mark this property with JsonProperty attribute
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public SaleLines SaleLines { get; set; }
Upvotes: 1