我正在将我的.NET Core 3.0应用程序从Newtonsoft.Json
迁移到System.Text.Json
。我想忽略false值。
在System.Text.Json
中,我找到了忽略null值的选项:
JsonSerializerOptions.IgnoreNullValues = true;
但我找不到在System.Text.Json
中忽略false值的选项。
有人知道如何使用System.Text.Json
实现这一点吗?
或者如果有人知道Newtonsoft DefaultValueHandling = DefaultValueHandling.Ignore
选项的等效方法,那就太棒了。
JsonSerializer.Write.HandleObject.cs
是写入对象属性的地方。其中有一个检查jsonPropertyInfo.IgnoreNullValues
和jsonPropertyInfo.ShouldSerialize
的操作,但没有检查默认值,也没有检查自定义的ShouldSerializeXXX()
方法。 - dbc