2

I want to configure camlecase for JSON serialization in ASP.NET Core. I've found this solution. But it just works on MVC not WebApi.

So I've tested:

services.AddControllers().AddJsonOptions(options => {
    options.JsonSerializerOptions.DictionaryKeyPolicy = JsonNamingPolicy.CamelCase;
    options.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
        });

And it is not working in WebApi projects.

So the question is: How to configure Camel Case in ASP.NET Core WebApi projects.

1 Answers1

-5

In Startup.cs file

public virtual void ConfigureServices(IServiceCollection services)
{
    services.AddMvc()
        .AddJsonOptions(j =>
        {
            j.SerializerSettings.ContractResolver = new DefaultContractResolver()
            {
                NamingStrategy = new CamelCaseNamingStrategy()
            };
        });
}
Ravi
  • 408
  • 7
  • 22