private static IContractResolver GetContractResolver(JsonCaseStyle style, JsonResolverSettings settings) { switch (style) { case JsonCaseStyle.CamelCase: return(new ExtendedCamelCaseContractResolver(settings)); case JsonCaseStyle.PascalCase: default: return(new ExtendedContractResolver(settings)); } }
public void Test() { TestObject t1 = new TestObject() { DateTimeOffsetValue = DateTimeOffset.Now, NullableDateTimeOffsetValue = DateTimeOffset.Now.AddDays(1), DateTimeValue = DateTime.Now.AddMinutes(3), NullableDateTimeValue = DateTime.Now.AddHours(1), LongValue = 9898989L, NullableLongValue = 7777777L }; var resolver = new JsonResolverSettings(); resolver.DateTimeToString.Enable = true; resolver.LongToString.Enable = true; JsonSerializerSettings settings = new JsonSerializerSettings(); settings.ContractResolver = new ExtendedCamelCaseContractResolver(resolver); var json = JsonConvert.SerializeObject(t1, settings); var t11 = JsonConvert.DeserializeObject <TestObject>(json, settings); TestObject t2 = new TestObject() { DateTimeOffsetValue = DateTimeOffset.Now, NullableDateTimeOffsetValue = null, DateTimeValue = DateTime.Now.AddMinutes(3), NullableDateTimeValue = null, LongValue = 9898989L, NullableLongValue = null, }; json = JsonConvert.SerializeObject(t2, settings); var t12 = JsonConvert.DeserializeObject <TestObject>(json, settings); }