public static void Main() { string json = "{'name': 'Joel', 'is_css_noob': true}"; var resolver = new StandardContractResolver { // split the property into words by camel case and acronyms WordSplitOptions = WordSplitOptions.SplitCamelCase | WordSplitOptions.SplitAcronyms, // each output word should be lowercase CapitalizationOptions = CapitalizationOptions.AllLowercase, // join the words by underscores WordDelimiter = "_" }; var settings = new JsonSerializerSettings { ContractResolver = resolver }; var d = JsonConvert.DeserializeObject <Developer>(json, settings); Console.WriteLine( "{0} is {1} a CSS noob.", d.Name, d.IsCSSNoob ? "pretty much" : "not"); }
public void GetResolvedPropertyNameWithNullPropertyNameThrwsArgumentNullException() { // ARRANGE var resolver = new StandardContractResolver(); // ACT, ASSERT AssertExtensions.Throws <ArgumentNullException>( () => resolver.GetResolvedPropertyName(null), e => Assert.AreEqual("propertyName", e.ParamName)); }
static RottenTomatoesDeserializer() { var resolver = new StandardContractResolver { WordSplitOptions = WordSplitOptions.SplitCamelCase, CapitalizationOptions = CapitalizationOptions.AllLowercase, WordDelimiter = "_" }; JsonSerializerSettings = new JsonSerializerSettings { ContractResolver = resolver }; }
private static void VerifyGetResolvedPropertyName(WordSplitOptions wordSplitOptions, CapitalizationOptions capitalizationOptions, string wordDelimiter, string input, string expected) { // ARRANGE var resolver = new StandardContractResolver { WordSplitOptions = wordSplitOptions, CapitalizationOptions = capitalizationOptions, WordDelimiter = wordDelimiter }; // ACT string actual = resolver.GetResolvedPropertyName(input); // ASSERT Assert.AreEqual(expected, actual); }
private static JsonMediaTypeFormatter GetJsonMediaTypeFormatter() { var resolver = new StandardContractResolver { CapitalizationOptions = CapitalizationOptions.AllLowercase, WordSplitOptions = WordSplitOptions.SplitCamelCase, WordDelimiter = "_" }; var serializerSettings = new JsonSerializerSettings { ContractResolver = resolver }; serializerSettings.Converters.Add(new StringEnumConverter()); return(new JsonpMediaTypeFormatter { UseDataContractJsonSerializer = false, SerializerSettings = serializerSettings }); }