JsonSerializerSettings and Asp.Net Core

.Net Core 1.0 RTM comes with CamelCase formatting out-of-the-box. This is a behavior change from RC2. However, if you need to modify it, try this snippet:

services.AddMvc()
        .AddJsonOptions(opt =>
    {
        var resolver  = opt.SerializerSettings.ContractResolver;
        if (resolver != null)
        {
            var res = resolver as DefaultContractResolver;
            res.NamingStrategy = null;  // <<!-- this removes the camelcasing
        }
    });

More information here.

For dotnet core 1.0.1:

  services
            .AddMvcCore()
            .AddJsonFormatters(o => o...);

Leave a Comment