Home >Backend Development >C++ >Why is `IMvcBuilder.AddJsonOptions` Missing in ASP.NET Core 3.0 and How Can I Configure JSON Serialization?
The IMvcBuilder.AddJsonOptions method is missing and the JSON serialization configuration solution in ASP.NET Core 3.0
Problem Description
After upgrading the ASP.NET Web API project from .NET Core 2.0 to 3.0, using IMvcBuilder.AddJsonOptions
will report an error, prompting that IMvcBuilder
no longer contains this extension method.
Solution
Adopt new JSON API
ASP.NET Core 3.0 no longer uses Json.NET by default in favor of the new high-performance JSON API.
Reconfigure Json.NET (optional)
For compatibility with older projects, you can reconfigure your project to use Json.NET:
Microsoft.AspNetCore.Mvc.NewtonsoftJson
NuGet package. Startup.cs
method of the ConfigureServices
file: <code class="language-csharp">services.AddControllers() .AddNewtonsoftJson();</code>
<code class="language-csharp">services.AddControllers() .AddNewtonsoftJson(options => { options.SerializerSettings.ContractResolver = new DefaultContractResolver(); });</code>
The above is the detailed content of Why is `IMvcBuilder.AddJsonOptions` Missing in ASP.NET Core 3.0 and How Can I Configure JSON Serialization?. For more information, please follow other related articles on the PHP Chinese website!