如何设置JsonSerializer
忽略默认值0001-01-01T00:00:00
的DateTime属性,但是同时使用默认值序列化枚举和数字?
这也忽略了枚举:
_jsonSerializer = new JsonSerializer();
_jsonSerializer.DefaultValueHandling = DefaultValueHandling.Ignore;
这也包括默认日期时间:
_jsonSerializer.DefaultValueHandling = DefaultValueHandling.Include;
答案 0 :(得分:0)
我想这是类似的问题并得到回答:Exclude property from serialization via custom attribute (json.net)
它指的是json.net docs中的Conditional Property Serialization文章
_jsonSerializer.DefaultValueHandling = DefaultValueHandling.Include;
_jsonSerializer.ContractResolver = new MyShouldSerializeContractResolver();