AddJsonOptions
method in ASP.NET Core 3.0Problem: After upgrading to ASP.NET Core 3.0, the AddJsonOptions
method disappeared and reinstalling the dependencies did not solve the problem.
Answer:
Background:
ASP.NET Core 3.0 changes the default JSON serialization mechanism. Json.NET has been replaced by a new, performance-focused JSON API.
Use Json.NET:
If you require Json.NET compatibility, please follow these steps:
Microsoft.AspNetCore.Mvc.NewtonsoftJson
NuGet package. Startup
method of the ConfigureServices
class, configure MVC with the following code: <code class="language-csharp">services.AddControllers() .AddNewtonsoftJson();</code>
Configuration options:
You can further configure Json.NET options using overloaded methods:
<code class="language-csharp">services.AddControllers() .AddNewtonsoftJson(options => { options.SerializerSettings.ContractResolver = new DefaultContractResolver(); });</code>
The above is the detailed content of ASP.NET Core 3.0: Where Did `AddJsonOptions` Go?. For more information, please follow other related articles on the PHP Chinese website!