-Added documentation (gasp!)
-Fixed serialization of Uri members on Silverlight/Compact Framework -Fixed serialization of JToken members -Fixed (hopefully) cache threading issues
This commit is contained in:
@@ -2573,5 +2573,55 @@ keyword such as type of business.""
|
||||
Assert.AreEqual("Medium", deserializedProduct.Sizes[1]);
|
||||
Assert.AreEqual("Large", deserializedProduct.Sizes[2]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NestedInsideOuterObject()
|
||||
{
|
||||
string json = @"{
|
||||
""short"": {
|
||||
""original"": ""http://www.contrast.ie/blog/online-marketing-2009/"",
|
||||
""short"": ""m2sqc6"",
|
||||
""shortened"": ""http://short.ie/m2sqc6"",
|
||||
""error"": {
|
||||
""code"": 0,
|
||||
""msg"": ""No action taken""
|
||||
}
|
||||
}
|
||||
}";
|
||||
|
||||
JObject o = JObject.Parse(json);
|
||||
|
||||
Shortie s = JsonConvert.DeserializeObject<Shortie>(o["short"].ToString());
|
||||
Assert.IsNotNull(s);
|
||||
|
||||
Assert.AreEqual(s.Original, "http://www.contrast.ie/blog/online-marketing-2009/");
|
||||
Assert.AreEqual(s.Short, "m2sqc6");
|
||||
Assert.AreEqual(s.Shortened, "http://short.ie/m2sqc6");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UriSerialization()
|
||||
{
|
||||
Uri uri = new Uri("http://codeplex.com");
|
||||
string json = JsonConvert.SerializeObject(uri);
|
||||
|
||||
Assert.AreEqual("http://codeplex.com/", uri.ToString());
|
||||
|
||||
Uri newUri = JsonConvert.DeserializeObject<Uri>(json);
|
||||
Assert.AreEqual(uri, newUri);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AnonymousPlusLinqToSql()
|
||||
{
|
||||
var value = new
|
||||
{
|
||||
bar = new JObject(new JProperty("baz", 13))
|
||||
};
|
||||
|
||||
string json = JsonConvert.SerializeObject(value);
|
||||
|
||||
Assert.AreEqual(@"{""bar"":{""baz"":13}}", json);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -454,5 +454,37 @@ Parameter name: arrayIndex")]
|
||||
Console.WriteLine(name);
|
||||
Console.WriteLine(smallest);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void sdfs()
|
||||
{
|
||||
string jsonText = @"{
|
||||
""short"":{
|
||||
""original"":""http://www.foo.com/"",
|
||||
""short"":""krehqk"",
|
||||
""error"":{
|
||||
""code"":0,
|
||||
""msg"":""No action taken""}
|
||||
}";
|
||||
|
||||
JObject json = JObject.Parse(jsonText);
|
||||
|
||||
Shortie shortie = new Shortie
|
||||
{
|
||||
Original = (string)json["short"]["original"],
|
||||
Short = (string)json["short"]["short"],
|
||||
Error = new ShortieException
|
||||
{
|
||||
Code = (int)json["short"]["error"]["code"],
|
||||
ErrorMessage = (string)json["short"]["error"]["msg"]
|
||||
}
|
||||
};
|
||||
|
||||
Assert.AreEqual("http://www.foo.com/", shortie.Original);
|
||||
Assert.AreEqual("krehqk", shortie.Short);
|
||||
Assert.AreEqual(null, shortie.Shortened);
|
||||
Assert.AreEqual(0, shortie.Error.Code);
|
||||
Assert.AreEqual("No action taken", shortie.Error.ErrorMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,6 +110,7 @@
|
||||
<Compile Include="TestObjects\Product.cs" />
|
||||
<Compile Include="TestObjects\ProductCollection.cs" />
|
||||
<Compile Include="TestObjects\ProductShort.cs" />
|
||||
<Compile Include="TestObjects\Shortie.cs" />
|
||||
<Compile Include="TestObjects\Store.cs" />
|
||||
<Compile Include="TestObjects\StoreColor.cs" />
|
||||
<Compile Include="TestObjects\Person.cs" />
|
||||
|
||||
@@ -114,6 +114,7 @@
|
||||
<Compile Include="TestObjects\Product.cs" />
|
||||
<Compile Include="TestObjects\ProductCollection.cs" />
|
||||
<Compile Include="TestObjects\ProductShort.cs" />
|
||||
<Compile Include="TestObjects\Shortie.cs" />
|
||||
<Compile Include="TestObjects\Store.cs" />
|
||||
<Compile Include="TestObjects\StoreColor.cs" />
|
||||
<Compile Include="TestObjects\Person.cs" />
|
||||
|
||||
@@ -143,6 +143,7 @@
|
||||
<Compile Include="TestObjects\Product.cs" />
|
||||
<Compile Include="TestObjects\ProductCollection.cs" />
|
||||
<Compile Include="TestObjects\ProductShort.cs" />
|
||||
<Compile Include="TestObjects\Shortie.cs" />
|
||||
<Compile Include="TestObjects\Store.cs" />
|
||||
<Compile Include="TestObjects\StoreColor.cs" />
|
||||
<Compile Include="TestObjects\Person.cs" />
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.TestObjects
|
||||
{
|
||||
[XmlRoot("short")]
|
||||
[JsonObject(MemberSerialization.OptIn)]
|
||||
public class Shortie
|
||||
{
|
||||
[JsonProperty("original")]
|
||||
[XmlElement("original")]
|
||||
public String Original { get; set; }
|
||||
|
||||
[JsonProperty("shortened")]
|
||||
[XmlElement("shortened")]
|
||||
public String Shortened { get; set; }
|
||||
|
||||
[JsonProperty("short")]
|
||||
[XmlElement("short")]
|
||||
public String Short { get; set; }
|
||||
|
||||
public ShortieException Error { get; set; }
|
||||
}
|
||||
|
||||
public class ShortieException
|
||||
{
|
||||
[JsonProperty("code")]
|
||||
[XmlElement("code")]
|
||||
public int Code { get; set; }
|
||||
|
||||
[JsonProperty("msg")]
|
||||
[XmlElement("msg")]
|
||||
public String ErrorMessage { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user