diff options
author | JamesNK <james@newtonking.com> | 2010-12-27 07:14:24 +0300 |
---|---|---|
committer | JamesNK <james@newtonking.com> | 2010-12-27 07:14:24 +0300 |
commit | 1297d64457363c37cc2794cf2031492400179336 (patch) | |
tree | bbcbe3917450d97660a6f168c146c43a9b0ce813 | |
parent | 87a2bbf831b1307f8763059872fa74203c60e09e (diff) |
-Fixed DataSetConverter deserializing DataSet properties
-rw-r--r-- | Src/Newtonsoft.Json.Tests/Converters/DataSetConverterTests.cs | 65 | ||||
-rw-r--r-- | Src/Newtonsoft.Json/Converters/DataSetConverter.cs | 2 |
2 files changed, 65 insertions, 2 deletions
diff --git a/Src/Newtonsoft.Json.Tests/Converters/DataSetConverterTests.cs b/Src/Newtonsoft.Json.Tests/Converters/DataSetConverterTests.cs index 9c4abf9..abea61f 100644 --- a/Src/Newtonsoft.Json.Tests/Converters/DataSetConverterTests.cs +++ b/Src/Newtonsoft.Json.Tests/Converters/DataSetConverterTests.cs @@ -240,6 +240,71 @@ namespace Newtonsoft.Json.Tests.Converters return myTable;
}
+
+ public class DataSetTestClass
+ {
+ public string Before { get; set; }
+ public DataSet Data { get; set; }
+ public string After { get; set; }
+ }
+
+ [Test]
+ public void Blah()
+ {
+ DataSet ds = new DataSet();
+ ds.Tables.Add(CreateDataTable("FirstTable", 2));
+ ds.Tables.Add(CreateDataTable("SecondTable", 1));
+
+ DataSetTestClass c = new DataSetTestClass
+ {
+ Before = "Before",
+ Data = ds,
+ After = "After"
+ };
+
+ string json = JsonConvert.SerializeObject(c, Formatting.Indented, new IsoDateTimeConverter());
+
+ Assert.AreEqual(@"{
+ ""Before"": ""Before"",
+ ""Data"": {
+ ""FirstTable"": [
+ {
+ ""StringCol"": ""Item Name"",
+ ""Int32Col"": 1,
+ ""BooleanCol"": true,
+ ""TimeSpanCol"": ""10.22:10:15.1000000"",
+ ""DateTimeCol"": ""2000-12-29T00:00:00Z"",
+ ""DecimalCol"": 64.0021
+ },
+ {
+ ""StringCol"": ""Item Name"",
+ ""Int32Col"": 2,
+ ""BooleanCol"": true,
+ ""TimeSpanCol"": ""10.22:10:15.1000000"",
+ ""DateTimeCol"": ""2000-12-29T00:00:00Z"",
+ ""DecimalCol"": 64.0021
+ }
+ ],
+ ""SecondTable"": [
+ {
+ ""StringCol"": ""Item Name"",
+ ""Int32Col"": 1,
+ ""BooleanCol"": true,
+ ""TimeSpanCol"": ""10.22:10:15.1000000"",
+ ""DateTimeCol"": ""2000-12-29T00:00:00Z"",
+ ""DecimalCol"": 64.0021
+ }
+ ]
+ },
+ ""After"": ""After""
+}", json);
+
+ DataSetTestClass c2 = JsonConvert.DeserializeObject<DataSetTestClass>(json, new IsoDateTimeConverter());
+
+ Assert.AreEqual(c.Before, c2.Before);
+ Assert.AreEqual(c.Data.Tables.Count, c2.Data.Tables.Count);
+ Assert.AreEqual(c.After, c2.After);
+ }
}
}
#endif
\ No newline at end of file diff --git a/Src/Newtonsoft.Json/Converters/DataSetConverter.cs b/Src/Newtonsoft.Json/Converters/DataSetConverter.cs index ef4e872..8d7aebf 100644 --- a/Src/Newtonsoft.Json/Converters/DataSetConverter.cs +++ b/Src/Newtonsoft.Json/Converters/DataSetConverter.cs @@ -80,8 +80,6 @@ namespace Newtonsoft.Json.Converters ds.Tables.Add(dt);
}
- reader.Read();
-
return ds;
}
|