using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization.Formatters;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
public int Identifier { get; set; }
public string Value { get; set; }
class LongNameContractResolver : DefaultContractResolver
protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization)
IList<JsonProperty> list = base.CreateProperties(type, memberSerialization);
foreach (JsonProperty prop in list)
prop.PropertyName = prop.UnderlyingName;
public static void Test()
Test<RootObject []>(GetJson(), new DefaultContractResolver());
Test<RootObject []>(GetUnderlingNameJson(), new LongNameContractResolver());
public static void Test<T>(string json, IContractResolver resolver)
Console.WriteLine("\nDeserializing JSON \"{0}\" to {1} with contract resolver {2}:", json, typeof(T), resolver);
var settings = new JsonSerializerSettings
ContractResolver = resolver
var root = JsonConvert.DeserializeObject<T>(json, settings);
Console.WriteLine("Result: ");
Console.WriteLine(JsonConvert.SerializeObject(root));
var json = @"[{ id: 1, text: ""two""}]";
static string GetUnderlingNameJson()
var json = @"[{ Identifier: 1, Value: ""two""}]";
public static void Main()
Console.WriteLine("Environment version: " + Environment.Version);
Console.WriteLine("Json.NET version: " + typeof(JsonSerializer).Assembly.FullName);
Console.WriteLine("Failed with unhandled exception: ");