Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AddJsonFormatters() missing after migration from .NET Core 2.2 to 3.0

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...
}
like image 878
Tonyc Avatar asked Oct 23 '19 14:10

Tonyc


1 Answers

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();
    })
like image 193
Clara Ruiz Avatar answered Oct 22 '22 21:10

Clara Ruiz