json - 使用新的 Net Core 3.0 Json 时忽略属性

标签 json json.net asp.net-core-3.0 .net-core-3.0 system.text.json

在 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/

相关文章:

c# - JSonNet bool 序列化

C# 操作 JSON 数据

c# - 在 .NET Core 3.0 中的集成测试中创建未经身份验证的请求

json - 为什么 Elasticsearch Bulk-API 使用 "Content-Type: application/json" header ?

c# - 如何将属性应用于继承树中的单个类型?

java - Java 中是否可以使用文件的内容类型来确定其文件类型?

javascript - 无法从 RCL 引用静态文件

angular - ASP.NET Core 3 - Angular SPA PWA

iOS NSDictionary 值确定 bool 值是否来自 JSON bool 值

javascript - PHP 将 JSON 对象返回给 Javascript [AJAX CALL] 不起作用