JSON properties now lower case on swap from ASP .Net Core 1.0.0-rc2-final to 1.0.0

后端 未结 8 1996
逝去的感伤
逝去的感伤 2020-12-08 12:54

I\'ve just swapped our project from ASP .Net Core 1.0.0-rc2-final to 1.0.0. Our website and client have stopped working because of the capitalization of JSON properties. For

相关标签:
8条回答
  • 2020-12-08 13:55

    For Core 2.x versions, using this code you can avoid camel case names by default. You need to add following code inside the ConfigureServices method of Startup.cs file.

    services.AddMvc()
    .AddJsonOptions(o =>
    {
        if (o.SerializerSettings.ContractResolver != null)
        {
            var castedResolver = o.SerializerSettings.ContractResolver
            as DefaultContractResolver;
    
            castedResolver.NamingStrategy = null;
        }
    });
    
    0 讨论(0)
  • 2020-12-08 13:56

    This will fix it in dotnet core 3 webapi, so that it doesn't change your property names at all, and you return to your client exactly what you intended to.

    In Startup.cs:

    public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers().AddJsonOptions(options => options.JsonSerializerOptions.PropertyNamingPolicy = null);
            services.AddHttpClient();
        }
    
    0 讨论(0)
提交回复
热议问题