Consider the following scenario:
var s1 = "{\"hello\":\"world\", \"test\":\"somevalue\"}";
var s2 = "{\"hello\":\"world\", \"test\":null}";
var j1 = JObject.Parse(s1);
var j2 = JObject.Parse(s2);
j1.Merge(j2, new JsonMergeSettings { MergeArrayHandling = MergeArrayHandling.Union, MergeNullValueHandling = MergeNullValueHandling.Merge });
var jf = JsonConvert.SerializeObject(j1, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
The result of jf
is {"hello":"world", "test":null}
How would I invoke the library for the result of the merge to be:
{"hello":"world"}
Is this a case where i'd have to recursively go through the resultant object and remove null value'd properties manually? Or is there some magic-wand that says "just drop these null values when serializing"
I know about the JsonProperty -> NullValueHandling
, but these are dynamic objects I am working with, so the model is unknown.