Web API serialize properties starting from lowercase letter

后端 未结 4 1173
故里飘歌
故里飘歌 2020-12-04 16:46

How can I configure serialization of my Web API to use camelCase (starting from lowercase letter) property names instead of PascalCase like it is i

4条回答
  •  执笔经年
    2020-12-04 17:01

    For MVC 6.0.0-rc1-final

    Edit Startup.cs, In the ConfigureServices(IserviceCollection), modify services.AddMvc();

    services.AddMvc(options =>
    {
        var formatter = new JsonOutputFormatter
        {
            SerializerSettings = {ContractResolver = new CamelCasePropertyNamesContractResolver()}
        };
        options.OutputFormatters.Insert(0, formatter);
    });
    

提交回复
热议问题