Default camel case of property names in JSON serialization

后端 未结 7 1058
感情败类
感情败类 2020-12-14 00:35

I have a bunch of classes that will be serialized to JSON at some point and for the sake of following both C# conventions on the back-end and JavaScript conventions on the f

7条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-14 00:54

    Better to use the new CamelCaseNamingStrategy (since 9.0.1):

    new JsonSerializerSettings()
    {
        ContractResolver = new DefaultContractResolver
        {
           NamingStrategy = new CamelCaseNamingStrategy()
        }
    };
    

    It does not override custom names set by JsonPropert('Name') by default. (You can change the behaviour by CamelCaseNamingStrategy(bool, bool) ctor.) So, does not need to create custom class like @Matt Burland's answer.

提交回复
热议问题