I am talking to an webservice that that can return the following JSON structure:
{
"foo": {
"bar": "hello world"
}
}
Foo is optional, but instead of the value NULL, we get the following:
{
"foo": []
}
An empty array. I used an (ugly) work around for this by using the following properties in my model:
public dynamic Foo { get; set; }
public FooModel FooObject {
get
{
if(Foo == null || Foo.GetType().IsArray)
{
return null;
}
return ((JObject)Foo).ToObject<FooModel>();
}
}
This works for this single property. But the webservice does this for all objects that are NULL. I'm looking for a generic solution that ignores all empty arrays when deserialization. (or something else)
I haven't been able to find a solution. I tried looking into using an custom JsonConverter and ContractResolver.