在 ASP.Net Core 2.2 中使用 JSON.Net 时,当序列化为 JSON 时,当其值为 null 时,我能够忽略属性:
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public DateTime? Created { get; set; }
但是,当使用内置于 JSON (System.Text.Json) 的新 ASP.Net Core 3.0 时,如果某个属性的值为 null,我找不到可以忽略该属性的等效属性。
我只能找到 JsonIgnore。
我错过了什么吗?
最佳答案
这是在 .Net 5 上修复的
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
请参阅下面的更新https://github.com/dotnet/runtime/issues/41313
https://github.com/dotnet/runtime/issues/30687
关于json - 使用新的 Net Core 3.0 Json 时忽略属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58106558/