I have a Net Core 2.2 Web Api that I protect with the integration of IdentityServer4. So I started from the tutorial of IDS4 to write the code and there I found the AddJsonFormatters().
I'm triyng to migrate it from .NET Core 2.2 to .NET Core 3.0.
At the moment I have a problem at compile time in the ConfigureServices().
I don't find the AddJsonFormatters() and if I correctly understand, I have to use the AddMvcOptions() to get the same result.
Is this correct? In this case, what is the equivalent configuration?
// .NET Core 2.2
public void ConfigureServices(IServiceCollection services)
{
services.AddMvcCore()
.AddAuthorization()
.AddJsonFormatters();
// Other code...
}
// .NET Core 3.0
public void ConfigureServices(IServiceCollection services)
{
services.AddMvcCore()
.AddAuthorization()
// Something like this...
.AddMvcOptions(options =>
{
//options.OutputFormatters.Add(new SomeKindOf_IOutputFormatter());
//options.InputFormatters.Add(new SomeKindOf_IInputFormatter(options));
});
// Other code...
}
You can use Microsoft.AspNetCore.Mvc.NewtonsoftJson NuGet package, and configure it in the Startup.cs:
services.AddMvcCore()
.AddNewtonsoftJson(o =>
{
o.SerializerSettings.Converters.Add(new StringEnumConverter());
o.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With