Permalink
Browse files

-Added DateFormatHandling to control whether dates are written in the…

… MS format or ISO format, with ISO as the default

-Added DateTimeZoneHandling to control reading and writing DateTime time zone details
-Added reader/writer specific Formatting, DateFormatHandling and DateTimeZoneHandling to JsonSerializerSettings
-Added feature of reader/writer specific settings to be set on JsonReader/JsonWriter when serializing
-Added ReadAsDate to JsonReader
-Added ReadAsString to JsonReader
-Changed JsonTextReader to automatically read ISO strings as dates
-Refactored ReadAsXXX methods and reduce code redundancy
-Removed unused JsonDateTimeSerializationMode
  • Loading branch information...
JamesNK committed Mar 4, 2012
1 parent fb2a599 commit fd760e33898cc6b3badaf4a8b77a466139b87fac
Showing with 1,726 additions and 824 deletions.
  1. +5 −5 Src/Newtonsoft.Json.Tests/Converters/DataSetConverterTests.cs
  2. +1 −1 Src/Newtonsoft.Json.Tests/Converters/DataTableConverterTests.cs
  3. +0 −40 Src/Newtonsoft.Json.Tests/Converters/IsoDateTimeConverterTests.cs
  4. +309 −7 Src/Newtonsoft.Json.Tests/JsonConvertTest.cs
  5. +4 −4 Src/Newtonsoft.Json.Tests/JsonTextReaderTest.cs
  6. +6 −2 Src/Newtonsoft.Json.Tests/JsonTextWriterTest.cs
  7. +4 −4 Src/Newtonsoft.Json.Tests/Linq/JTokenReaderTest.cs
  8. +2 −2 Src/Newtonsoft.Json.Tests/Linq/LinqToJsonTest.cs
  9. +65 −6 Src/Newtonsoft.Json.Tests/PerformanceTests.cs
  10. +1 −1 Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs
  11. +5 −5 Src/Newtonsoft.Json.Tests/Serialization/CamelCasePropertyNamesContractResolverTests.cs
  12. +1 −1 Src/Newtonsoft.Json.Tests/Serialization/ContractResolverTests.cs
  13. +205 −21 Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs
  14. +1 −1 Src/Newtonsoft.Json.Tests/Serialization/NullValueHandlingTests.cs
  15. +2 −2 Src/Newtonsoft.Json.Tests/Serialization/SerializationErrorHandlingTests.cs
  16. +3 −3 Src/Newtonsoft.Json.Tests/Serialization/TypeNameHandlingTests.cs
  17. +11 −0 Src/Newtonsoft.Json.Tests/TestFixtureBase.cs
  18. +27 −128 Src/Newtonsoft.Json/Bson/BsonReader.cs
  19. +10 −0 Src/Newtonsoft.Json/Converters/IsoDateTimeConverter.cs
  20. +0 −30 Src/Newtonsoft.Json/Converters/JsonDateTimeSerializationMode.cs
  21. +8 −0 Src/Newtonsoft.Json/DateFormatHandling.cs
  22. +28 −0 Src/Newtonsoft.Json/DateTimeZoneHandling.cs
  23. +17 −0 Src/Newtonsoft.Json/Formatting.cs
  24. +151 −24 Src/Newtonsoft.Json/JsonConvert.cs
  25. +70 −0 Src/Newtonsoft.Json/JsonPosition.cs
  26. +344 −66 Src/Newtonsoft.Json/JsonReader.cs
  27. +88 −2 Src/Newtonsoft.Json/JsonSerializer.cs
  28. +37 −0 Src/Newtonsoft.Json/JsonSerializerSettings.cs
  29. +137 −256 Src/Newtonsoft.Json/JsonTextReader.cs
  30. +5 −2 Src/Newtonsoft.Json/JsonTextWriter.cs
  31. +24 −0 Src/Newtonsoft.Json/JsonValidatingReader.cs
  32. +16 −52 Src/Newtonsoft.Json/JsonWriter.cs
  33. +33 −142 Src/Newtonsoft.Json/Linq/JTokenReader.cs
  34. +8 −1 Src/Newtonsoft.Json/Newtonsoft.Json.Net20.csproj
  35. +8 −1 Src/Newtonsoft.Json/Newtonsoft.Json.Net35.csproj
  36. +5 −1 Src/Newtonsoft.Json/Newtonsoft.Json.Silverlight.csproj
  37. +5 −1 Src/Newtonsoft.Json/Newtonsoft.Json.WindowsPhone.csproj
  38. +5 −1 Src/Newtonsoft.Json/Newtonsoft.Json.csproj
  39. +1 −1 Src/Newtonsoft.Json/Properties/AssemblyInfo.cs
  40. +8 −11 Src/Newtonsoft.Json/Serialization/JsonContract.cs
  41. +6 −0 Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs
  42. +19 −0 Src/Newtonsoft.Json/Serialization/JsonSerializerProxy.cs
  43. +41 −0 Src/Newtonsoft.Json/WriteState.cs
@@ -170,7 +170,7 @@ public void DeserializeMultiTableDataSet()
]
}";
DataSet ds = JsonConvert.DeserializeObject<DataSet>(json, new IsoDateTimeConverter());
DataSet ds = JsonConvert.DeserializeObject<DataSet>(json);
Assert.IsNotNull(ds);
Assert.AreEqual(2, ds.Tables.Count);
@@ -187,7 +187,7 @@ public void DeserializeMultiTableDataSet()
Assert.AreEqual("TimeSpanCol", dt.Columns[3].ColumnName);
Assert.AreEqual(typeof(string), dt.Columns[3].DataType);
Assert.AreEqual("DateTimeCol", dt.Columns[4].ColumnName);
Assert.AreEqual(typeof(string), dt.Columns[4].DataType);
Assert.AreEqual(typeof(DateTime), dt.Columns[4].DataType);
Assert.AreEqual("DecimalCol", dt.Columns[5].ColumnName);
Assert.AreEqual(typeof(double), dt.Columns[5].DataType);
@@ -270,15 +270,15 @@ public void SerializeWithCamelCaseResolver()
""int32Col"": 1,
""booleanCol"": true,
""timeSpanCol"": ""10.22:10:15.1000000"",
""dateTimeCol"": ""\/Date(978048000000)\/"",
""dateTimeCol"": ""2000-12-29T00:00:00Z"",
""decimalCol"": 64.0021
},
{
""stringCol"": ""Item Name"",
""int32Col"": 2,
""booleanCol"": true,
""timeSpanCol"": ""10.22:10:15.1000000"",
""dateTimeCol"": ""\/Date(978048000000)\/"",
""dateTimeCol"": ""2000-12-29T00:00:00Z"",
""decimalCol"": 64.0021
}
],
@@ -288,7 +288,7 @@ public void SerializeWithCamelCaseResolver()
""int32Col"": 1,
""booleanCol"": true,
""timeSpanCol"": ""10.22:10:15.1000000"",
""dateTimeCol"": ""\/Date(978048000000)\/"",
""dateTimeCol"": ""2000-12-29T00:00:00Z"",
""decimalCol"": 64.0021
}
]
@@ -97,7 +97,7 @@ public void Serialize()
""Int32Col"": 2147483647,
""BooleanCol"": true,
""TimeSpanCol"": ""10.22:10:15.1000000"",
""DateTimeCol"": ""\/Date(978048000000)\/"",
""DateTimeCol"": ""2000-12-29T00:00:00Z"",
""DecimalCol"": 64.0021
}
]", json);
@@ -201,46 +201,6 @@ public void NullableSerializeUTC()
Assert.AreEqual(@"{""PreField"":""Pre"",""DateTimeField"":null,""DateTimeOffsetField"":null,""PostField"":""Post""}", json);
}
[Test]
public void DeserializeUTC()
{
DateTimeTestClass c =
JsonConvert.DeserializeObject<DateTimeTestClass>(@"{""PreField"":""Pre"",""DateTimeField"":""2008-12-12T12:12:12Z"",""DateTimeOffsetField"":""2008-12-12T12:12:12Z"",""PostField"":""Post""}", new IsoDateTimeConverter() { DateTimeStyles = DateTimeStyles.AssumeUniversal });
Assert.AreEqual(new DateTime(2008, 12, 12, 12, 12, 12, 0, DateTimeKind.Utc).ToLocalTime(), c.DateTimeField);
Assert.AreEqual(new DateTimeOffset(2008, 12, 12, 12, 12, 12, 0, TimeSpan.Zero), c.DateTimeOffsetField);
Assert.AreEqual("Pre", c.PreField);
Assert.AreEqual("Post", c.PostField);
DateTimeTestClass c2 =
JsonConvert.DeserializeObject<DateTimeTestClass>(@"{""PreField"":""Pre"",""DateTimeField"":""2008-01-01T01:01:01Z"",""DateTimeOffsetField"":""2008-01-01T01:01:01Z"",""PostField"":""Post""}", new IsoDateTimeConverter() { DateTimeStyles = DateTimeStyles.AssumeUniversal });
Assert.AreEqual(new DateTime(2008, 1, 1, 1, 1, 1, 0, DateTimeKind.Utc).ToLocalTime(), c2.DateTimeField);
Assert.AreEqual(new DateTimeOffset(2008, 1, 1, 1, 1, 1, 0, TimeSpan.Zero), c2.DateTimeOffsetField);
Assert.AreEqual("Pre", c2.PreField);
Assert.AreEqual("Post", c2.PostField);
}
[Test]
public void NullableDeserializeUTC()
{
NullableDateTimeTestClass c =
JsonConvert.DeserializeObject<NullableDateTimeTestClass>(@"{""PreField"":""Pre"",""DateTimeField"":""2008-12-12T12:12:12Z"",""DateTimeOffsetField"":""2008-12-12T12:12:12Z"",""PostField"":""Post""}", new IsoDateTimeConverter() { DateTimeStyles = DateTimeStyles.AssumeUniversal });
Assert.AreEqual(new DateTime(2008, 12, 12, 12, 12, 12, 0, DateTimeKind.Utc).ToLocalTime(), c.DateTimeField);
Assert.AreEqual(new DateTimeOffset(2008, 12, 12, 12, 12, 12, 0, TimeSpan.Zero), c.DateTimeOffsetField);
Assert.AreEqual("Pre", c.PreField);
Assert.AreEqual("Post", c.PostField);
NullableDateTimeTestClass c2 =
JsonConvert.DeserializeObject<NullableDateTimeTestClass>(@"{""PreField"":""Pre"",""DateTimeField"":null,""DateTimeOffsetField"":null,""PostField"":""Post""}", new IsoDateTimeConverter() { DateTimeStyles = DateTimeStyles.AssumeUniversal });
Assert.AreEqual(null, c2.DateTimeField);
Assert.AreEqual(null, c2.DateTimeOffsetField);
Assert.AreEqual("Pre", c2.PreField);
Assert.AreEqual("Post", c2.PostField);
}
[Test]
public void NullableDeserializeEmptyString()
{
Oops, something went wrong.

0 comments on commit fd760e3

Please sign in to comment.