Rok*_*Rok 7 c# json.net asp.net-core-3.0 .net-core-3.0 system.text.json
我想在 .NET Core Web API 3.0.0 上显式使用遗留库进行序列化/反序列化。 Newtonsoft.Json无论我做什么,总是System.Text.Json涉及并且不使用定制的 Newtonsoft 转换器。
ConfigureServices中的方法startup.cs看起来像这样:
public void ConfigureServices(IServiceCollection services)
{
// ...
services.AddControllers()
.SetCompatibilityVersion(CompatibilityVersion.Version_3_0)
.AddNewtonsoftJson(options =>
{
options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
options.SerializerSettings.TypeNameHandling = TypeNameHandling.Auto;
options.SerializerSettings.Converters.Add(new CustomGeoJsonConverter());
}
);
// ...
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我尝试使用自定义CustomGeoJsonConverter,并且在序列化时,该对象中没有任何活动。类似的代码在 .NET Core 2.2 中运行正常。