4

I would like explicitly use legacy Newtonsoft.Json library for serialization/deserialization on .NET Core Web API 3.0.0. No mater what I do, always System.Text.Json is involved and custom Newtonsoft's converters are not used.

ConfigureServices method in startup.cs looks like this:

 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());
                    }
                );
// ...
}

In this case I tried with custom CustomGeoJsonConverter and, while serializing, there were no activity in that object. Similar code works OK in .NET Core 2.2.

4

0 回答 0