Skip to content

Commit

Permalink
-Demos
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesNK committed Aug 14, 2010
1 parent c8fa450 commit aae77b5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Build/build.ps1
@@ -1,5 +1,5 @@
properties {
$zipFileName = "Json35r7.zip"
$zipFileName = "Json35r8.zip"
$signAssemblies = $false
$signKeyPath = "D:\Development\Releases\newtonsoft.snk"
$buildDocumentation = $false
Expand Down
41 changes: 41 additions & 0 deletions Src/Newtonsoft.Json.Tests/Serialization/TypeNameHandlingTests.cs
Expand Up @@ -538,5 +538,46 @@ public void CollectionWithAbstractItems()
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; }
}
}

0 comments on commit aae77b5

Please sign in to comment.