c# - Jil serializer ignore null properties -
is there attribute prevent jil serializing properties null ?
in newtonsoft :
[jsonproperty(nullvaluehandling = nullvaluehandling.ignore)]
for whole object, excludenulls
parameter on options
want (many different options configurations pre-calced, options.excludenulls
works).
you can control serialization of single property conditional serialization. (i forgot option in original answer).
for example
class exampleclass { public string dontserializeifnull {get;set;} public string alwaysserialize {get;set;} public bool shouldserializedontserializeifnull() { return dontserializeifnull != null; } } json.serialize(new exampleclass { dontserializeifnull = null, alwaysserialize = null }); // {"alwaysserialize":null} json.serialize(new exampleclass { dontserializeifnull = "foo", alwaysserialize = null }); // {"alwaysserialize":null,"dontserializeifnull":"foo"} json.serialize(new exampleclass { dontserializeifnull = null, alwaysserialize = "bar" }); // {"alwaysserialize":"bar"} json.serialize(new exampleclass { dontserializeifnull = "foo", alwaysserialize = "bar" }); // {"alwaysserialize":"bar","dontserializeifnull":"foo"}
jil respects name
option on [datamember]
. suppose honoring emitdefaultvalue
wouldn't hardest thing, nobody's ever opened issue it.
Comments
Post a Comment