diff --git a/Doc/versions.txt b/Doc/versions.txt index 01e057b9..d19fc5cb 100644 --- a/Doc/versions.txt +++ b/Doc/versions.txt @@ -15,4 +15,7 @@ Json.NET comes in different versions for the various .NET frameworks. Silverlight 3.0 -Phone: - Windows Phone 7 \ No newline at end of file + Windows Phone 7 + +Microsoft stopped supporting the Compact Framework in Visual Studio 2010. +For a Compact Framework 3.5 build download Json.NET 3.5. \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/Linq/JObjectTests.cs b/Src/Newtonsoft.Json.Tests/Linq/JObjectTests.cs index 73e433b8..9bbdbf46 100644 --- a/Src/Newtonsoft.Json.Tests/Linq/JObjectTests.cs +++ b/Src/Newtonsoft.Json.Tests/Linq/JObjectTests.cs @@ -331,7 +331,7 @@ Parameter name: arrayIndex")] { string json = @"[new Date(1207285200000)]"; - JArray a = (JArray)JsonConvert.DeserializeObject(json, null); + JArray a = (JArray)JsonConvert.DeserializeObject(json); JValue v = (JValue)a[0]; Assert.AreEqual(JsonConvert.ConvertJavaScriptTicksToDateTime(1207285200000), (DateTime)v); diff --git a/Src/Newtonsoft.Json.Tests/Serialization/TypeNameHandlingTests.cs b/Src/Newtonsoft.Json.Tests/Serialization/TypeNameHandlingTests.cs index bf0ddc65..1a1dd32e 100644 --- a/Src/Newtonsoft.Json.Tests/Serialization/TypeNameHandlingTests.cs +++ b/Src/Newtonsoft.Json.Tests/Serialization/TypeNameHandlingTests.cs @@ -565,6 +565,55 @@ namespace Newtonsoft.Json.Tests.Serialization SearchDetails searchDetails = (SearchDetails) deserialized.Body; // Json.NET } + + public class UrlStatus + { + public int Status { get; set; } + public string Url { get; set; } + } + + + [Test] + public void GenericDictionaryObject() + { + Dictionary collection = new Dictionary() + { + {"First", new UrlStatus{ Status = 404, Url = @"http://www.bing.com"}}, + {"Second", new UrlStatus{Status = 400, Url = @"http://www.google.com"}} + }; + + string json = JsonConvert.SerializeObject(collection, Formatting.Indented, new JsonSerializerSettings + { + TypeNameHandling = TypeNameHandling.Objects, + TypeNameAssemblyFormat = FormatterAssemblyStyle.Simple + }); + + Assert.AreEqual(@"{ + ""$type"": ""System.Collections.Generic.Dictionary`2[[System.String, mscorlib],[System.Object, mscorlib]], mscorlib"", + ""First"": { + ""$type"": ""Newtonsoft.Json.Tests.Serialization.TypeNameHandlingTests+UrlStatus, Newtonsoft.Json.Tests"", + ""Status"": 404, + ""Url"": ""http://www.bing.com"" + }, + ""Second"": { + ""$type"": ""Newtonsoft.Json.Tests.Serialization.TypeNameHandlingTests+UrlStatus, Newtonsoft.Json.Tests"", + ""Status"": 400, + ""Url"": ""http://www.google.com"" + } +}", json); + + object c = JsonConvert.DeserializeObject(json, new JsonSerializerSettings + { + TypeNameHandling = TypeNameHandling.Objects, + TypeNameAssemblyFormat = FormatterAssemblyStyle.Simple + }); + + Assert.IsInstanceOfType(typeof(Dictionary), c); + + Dictionary newCollection = (Dictionary)c; + Assert.AreEqual(2, newCollection.Count); + Assert.AreEqual(@"http://www.bing.com", ((UrlStatus)newCollection["First"]).Url); + } } public class Message diff --git a/Src/Newtonsoft.Json/JsonConvert.cs b/Src/Newtonsoft.Json/JsonConvert.cs index c824cadc..54b9458b 100644 --- a/Src/Newtonsoft.Json/JsonConvert.cs +++ b/Src/Newtonsoft.Json/JsonConvert.cs @@ -595,9 +595,9 @@ namespace Newtonsoft.Json } /// - /// Deserializes the specified object to a Json object. + /// Deserializes the JSON to a .NET object. /// - /// The object to deserialize. + /// The JSON to deserialize. /// The deserialized object from the Json string. public static object DeserializeObject(string value) { @@ -605,9 +605,23 @@ namespace Newtonsoft.Json } /// - /// Deserializes the specified object to a Json object. + /// Deserializes the JSON to a .NET object. /// - /// The object to deserialize. + /// The JSON to deserialize. + /// + /// The used to deserialize the object. + /// If this is null, default serialization settings will be is used. + /// + /// The deserialized object from the JSON string. + public static object DeserializeObject(string value, JsonSerializerSettings settings) + { + return DeserializeObject(value, null, settings); + } + + /// + /// Deserializes the JSON to the specified .NET type. + /// + /// The JSON to deserialize. /// The of object being deserialized. /// The deserialized object from the Json string. public static object DeserializeObject(string value, Type type) @@ -616,10 +630,10 @@ namespace Newtonsoft.Json } /// - /// Deserializes the specified object to a Json object. + /// Deserializes the JSON to the specified .NET type. /// - /// The type of the object to deserialize. - /// The object to deserialize. + /// The type of the object to deserialize to. + /// The JSON to deserialize. /// The deserialized object from the Json string. public static T DeserializeObject(string value) { @@ -627,14 +641,14 @@ namespace Newtonsoft.Json } /// - /// Deserializes the specified JSON to the given anonymous type. + /// Deserializes the JSON to the given anonymous type. /// /// /// The anonymous type to deserialize to. This can't be specified /// traditionally and must be infered from the anonymous type passed /// as a parameter. /// - /// The object to deserialize. + /// The JSON to deserialize. /// The anonymous type object. /// The deserialized anonymous type from the JSON string. public static T DeserializeAnonymousType(string value, T anonymousTypeObject) @@ -643,10 +657,10 @@ namespace Newtonsoft.Json } /// - /// Deserializes the JSON string to the specified type. + /// Deserializes the JSON to the specified .NET type. /// - /// The type of the object to deserialize. - /// The object to deserialize. + /// The type of the object to deserialize to. + /// The JSON to deserialize. /// Converters to use while deserializing. /// The deserialized object from the JSON string. public static T DeserializeObject(string value, params JsonConverter[] converters) @@ -655,9 +669,9 @@ namespace Newtonsoft.Json } /// - /// Deserializes the JSON string to the specified type. + /// Deserializes the JSON to the specified .NET type. /// - /// The type of the object to deserialize. + /// The type of the object to deserialize to. /// The object to deserialize. /// /// The used to deserialize the object. @@ -670,9 +684,9 @@ namespace Newtonsoft.Json } /// - /// Deserializes the JSON string to the specified type. + /// Deserializes the JSON to the specified .NET type. /// - /// The object to deserialize. + /// The JSON to deserialize. /// The type of the object to deserialize. /// Converters to use while deserializing. /// The deserialized object from the JSON string. @@ -686,10 +700,10 @@ namespace Newtonsoft.Json } /// - /// Deserializes the JSON string to the specified type. + /// Deserializes the JSON to the specified .NET type. /// /// The JSON to deserialize. - /// The type of the object to deserialize. + /// The type of the object to deserialize to. /// /// The used to deserialize the object. /// If this is null, default serialization settings will be is used.