【发布时间】:2020-09-13 18:34:04
【问题描述】:
我在 .net core 3.1 中添加了 NewtonsoftJson 作为中间件。我很想转移到新的 System.Text.Json 序列化程序。
我不能只是跳过,但有没有办法以某种方法使用 System.Text.Json 中的那个。或多或少这是我需要加快速度的一个。
添加: 我在启动中
services.AddControllers(options => options.RespectBrowserAcceptHeader = true)
.AddNewtonsoftJson(options => options.SerializerSettings.ReferenceLoopHandling =
Newtonsoft.Json.ReferenceLoopHandling.Ignore);
我的迁移问题是我不能一次将其更改为 System.Text.Json。因此,如果我可以更改一个控制器或仅更改控制器中的一种方法以使用 System.Text.Json 版本,这将解决我的问题。
【问题讨论】:
-
我不知道您要迁移的 什么,因为您没有包含示例。请参阅official documentation 从 Newtonsoft 迁移到 System.Text。
-
参见System.Text.Json Reference Loop Handling - 请注意,发布的里程碑是 Net Core 5.0..
-
有没有办法以某种方式使用 System.Text.Json 中的那个。或多或少这是我需要加速的一个 - 只要您明确说明,您可能可以使用您想要的任何库。也许在您的问题中添加一些有关此的详细信息?
-
另请参阅当前迁移指南 How to migrate from Newtonsoft.Json to System.Text.Json: Scenarios that JsonSerializer currently doesn't support : Preserve object references and handle loops,其中指出
ReferenceLoopHandling.Ignore目前尚未实现。
标签: c# json .net-core system.text.json