首页 > 解决方案 > 是否可以在 asp.net 5.0 应用程序中使用 DataContractJsonSerializer 进行 json 序列化?

问题描述

我们有一个非常大的遗留 WCF Rest API,我们正在将其移植到 ASP.Net 5.0。移植到 ASP.Net 5.0 后,我们发现 JSON 序列化输出与原始遗留应用程序相比存在一些差异。在 ASP.Net Core 3.1 和 ASP.Net 5.0 中,默认的 JSON 序列化程序是 System.Text.Json ( https://devblogs.microsoft.com/dotnet/try-the-new-system-text-json-apis ),而在 WCF 中,默认的序列化程序是 WCF DataContractJsonSerializer。

我们正在考虑的一种选择是在我们的 .net 5.0 应用程序中使用 DataContractJsonSerializer。有没有办法将 ASP.Net 5.0 项目的 JSON 序列化程序从 System.Text.Json 库更改为 DataContractJsonSerializer 库?

我们看到有关如何在 asp.net 5.0 中从 System.Text.Json 更改为 Newtonsoft.Json 的帖子(例如,https://blogs.taiga.nl/martijn/2020/05/28/system-text-json- and-newtonsoft-json-side-by-side-in-asp-net-core/,在 Startup.ConfigureServices 方法中更改它),但我们一直无法找到一种方法来更改以使用 .净 5.0 应用程序。

是否有可能做到这一点?这需要编写自定义序列化代码吗?还是 DataContractJsonSerializer 与在 asp.net 5.0 应用程序中用作 json 序列化程序不兼容?

标签: c#asp.net-coreasp.net-core-5.0json-serializationdatacontractjsonserializer

解决方案


推荐阅读