Add Multiple Contract Resolver in Newtonsoft.Json

后端 未结 3 479
名媛妹妹
名媛妹妹 2020-12-17 15:16

Blueprint for data structure:

public class Movie
{
    public string Name { get; set; }
}

Using Newtonsoft.Json, I have the following confi

3条回答
  •  余生分开走
    2020-12-17 15:23

    Here is an alternative. Rather than using two ContractResolvers, you can use NamingStrategy instead of CamelCasePropertyNamesContractResolver.

    var settings = new JsonSerializerSettings()
    {
        ContractResolver = new NullToEmptyStringResolver(){NamingStrategy = new CamelCaseNamingStrategy()}
    };
    

    This is the similar @BrianRogers's second approach. I just didn't hard code the setting to NullToEmptyStringResolver class.

提交回复
热议问题