This commit is contained in:
JamesNK
2010-08-14 02:10:47 +00:00
parent c8fa450bed
commit aae77b5a43
2 changed files with 42 additions and 1 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
properties {
$zipFileName = "Json35r7.zip"
$zipFileName = "Json35r8.zip"
$signAssemblies = $false
$signKeyPath = "D:\Development\Releases\newtonsoft.snk"
$buildDocumentation = $false
@@ -538,5 +538,46 @@ namespace Newtonsoft.Json.Tests.Serialization
Assert.AreEqual(1, list.Count);
Assert.IsInstanceOfType(typeof(ContentSubClass), list[0]);
}
[Test]
public void WriteObjectTypeNameForPropertyDemo()
{
Message message = new Message();
message.Address = "http://www.google.com";
message.Body = new SearchDetails
{
Query = "Json.NET",
Language = "en-us"
};
string json = JsonConvert.SerializeObject(message, Formatting.Indented);
// {
// "Address": "http://www.google.com",
// "Body": {
// "$type": "Newtonsoft.Json.Tests.Serialization.SearchDetails, Newtonsoft.Json.Tests",
// "Query": "Json.NET",
// "Language": "en-us"
// }
// }
Message deserialized = JsonConvert.DeserializeObject<Message>(json);
SearchDetails searchDetails = (SearchDetails) deserialized.Body;
// Json.NET
}
}
public class Message
{
public string Address { get; set; }
[JsonProperty(TypeNameHandling = TypeNameHandling.All)]
public object Body { get; set; }
}
public class SearchDetails
{
public string Query { get; set; }
public string Language { get; set; }
}
}