.NET Core json serialization of properties on dynamic (ExpandoObject)

前端 未结 1 1927
一向
一向 2021-01-22 20:05

I have a web api in .NET Core 1.0 and I like the new feature that properties are by default serialized to camelCasing instead of PascalCasing.<

相关标签:
1条回答
  • 2021-01-22 20:48

    This can be solved with this in Startup.cs -> ConfigureServices:

    services.AddMvc().AddJsonOptions(opt =>
    {
        opt.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
    });
    

    It is mentioned a few places that this is now the default behavior for ASP.NET Core 1.0 but that is actually not true. Adding this line affects dynamic properties and those are not affected by default.

    0 讨论(0)
提交回复
热议问题