-Examples!

This commit is contained in:
James Newton-King
2013-01-26 14:46:05 +13:00
parent 406762b187
commit fd7970a3c3
113 changed files with 1279 additions and 101 deletions
+1 -1
View File
@@ -5,7 +5,7 @@
$version = GetVersion $majorWithReleaseVersion
$signAssemblies = $false
$signKeyPath = "D:\Development\Releases\newtonsoft.snk"
$buildDocumentation = $false
$buildDocumentation = $true
$buildNuGet = $false
$baseDir = resolve-path ..
+41
View File
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="Examples" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>Json.NET has the ability to conditionally serialize properties by placing a ShouldSerialize method on a class.
This funtionality is similar to the <externalLink>
<linkText>XmlSerializer ShouldSerialize feature</linkText>
<linkUri>http://msdn.microsoft.com/en-us/library/53b8022e.aspx</linkUri>
<linkTarget>_blank</linkTarget>
</externalLink>.</para>
</introduction>
<section>
<title>ShouldSerialize</title>
<content>
<para>To conditionally serialize a property add a boolean method with the same name as the property and then prefixed the method name
with ShouldSerialize. The result of the method determines whether the property is serialized. If the method returns true then the
property will be serialized, if it returns false and the property will be skipped.</para>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\ConditionalPropertiesTests.cs" region="EmployeeShouldSerializeExample" title="Employee class with a ShouldSerialize method" />
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\ConditionalPropertiesTests.cs" region="ShouldSerializeClassTest" title="ShouldSerialize output" />
</content>
</section>
<section>
<title>IContractResolver</title>
<content>
<para>ShouldSerialize can also be set using an <codeEntityReference>T:Newtonsoft.Json.Serialization.IContractResolver</codeEntityReference>.
Conditionally serializing a property using an IContractResolver is useful if you don't want to place a ShouldSerialize method on a class
or you didn't declare the class and are unable to.</para>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\ConditionalPropertiesTests.cs" region="ShouldSerializeContractResolver" title="Conditional properties with IContractResolver" />
</content>
</section>
<relatedTopics>
<codeEntityReference>T:Newtonsoft.Json.JsonSerializer</codeEntityReference>
<codeEntityReference>T:Newtonsoft.Json.Serialization.IContractResolver</codeEntityReference>
<codeEntityReference>P:Newtonsoft.Json.Serialization.JsonProperty.ShouldSerialize</codeEntityReference>
</relatedTopics>
</developerConceptualDocument>
</topic>
+70
View File
@@ -0,0 +1,70 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="Serializer" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<!--
<summary>
<para>Optional summary abstract</para>
</summary>
-->
<introduction>
<para>The <codeEntityReference>T:Newtonsoft.Json.Serialization.IContractResolver</codeEntityReference>
interface provides a way to customize how the
JsonSerializer serializes and deserializes .NET objects to JSON without placing attributes on your classes.
</para>
<para>Anything that can be set on an object, collection, property, etc, using attributes or methods to control serialization
can also be set using an IContractResolver.</para>
</introduction>
<!-- Add one or more top-level section elements. These are collapsible.
If using <autoOutline />, add an address attribute to identify it
and specify a title so that it can be jumped to with a hyperlink. -->
<section>
<title>DefaultContractResolver</title>
<content>
<!-- Uncomment this to create a sub-section outline
<autoOutline /> -->
<para>The <codeEntityReference>T:Newtonsoft.Json.Serialization.DefaultContractResolver</codeEntityReference>
is the default resolver used by the
serializer. It provides many avenues of extensibility in the form of
virtual methods that can be overriden.</para>
</content>
</section>
<section>
<title>CamelCasePropertyNamesContractResolver</title>
<content>
<!-- Uncomment this to create a sub-section outline
<autoOutline /> -->
<para><codeEntityReference>T:Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver</codeEntityReference>
inherits from DefaultContractResolver and simply overrides the JSON
property name to be written in <externalLink>
<linkText>camelcase</linkText>
<linkUri>http://en.wikipedia.org/wiki/CamelCase</linkUri>
<linkTarget>_blank</linkTarget>
</externalLink>.</para>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\SerializationTests.cs" region="ContractResolver" title="ContractResolver" />
</content>
</section>
<section>
<title>Custom IContractResolver Examples</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\PerformanceTests.cs" region="JsonConverterContractResolver" title="Use JsonConverter with IContractResolver" />
<para>This example sets a <codeEntityReference>T:Newtonsoft.Json.JsonConverter</codeEntityReference> for a type
using an IContractResolver. Using a contract resolver here is useful because DateTime is not your own type and it is not possible to place a JsonConverterAttribute on it.</para>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\ConditionalPropertiesTests.cs" region="ShouldSerializeContractResolver" title="Conditional properties with IContractResolver" />
<para>This example sets up <externalLink>
<linkText>conditional serialization for a property</linkText>
<linkUri>ConditionalProperties.htm</linkUri>
<linkTarget>_self</linkTarget>
</externalLink> using an IContractResolver. This is useful if you want to conditionally serialize a property but don't want to add additional methods to your type.</para>
</content>
</section>
<relatedTopics>
<codeEntityReference>T:Newtonsoft.Json.Serialization.IContractResolver</codeEntityReference>
<codeEntityReference>T:Newtonsoft.Json.Serialization.DefaultContractResolver</codeEntityReference>
<codeEntityReference>T:Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver</codeEntityReference>
</relatedTopics>
</developerConceptualDocument>
</topic>
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="CustomContractResolver" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This example creates a custom <codeEntityReference>T:Newtonsoft.Json.Serialization.IContractResolver</codeEntityReference>
that only serializes a type's properties that begin with a specified character.</para>
</introduction>
<section>
<title>Example</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\CustomContractResolver.cs" region="Types" title="Types" />
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\CustomContractResolver.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="CustomJsonConverter" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This example creates a custom <codeEntityReference>T:Newtonsoft.Json.JsonConverter</codeEntityReference>
that overrides serialization to add a keys property.</para>
</introduction>
<section>
<title>Example</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\CustomJsonConverter.cs" region="Types" title="Types" />
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\CustomJsonConverter.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="CustomTraceWriter" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This example creates a custom <codeEntityReference>T:Newtonsoft.Json.Serialization.ITraceWriter</codeEntityReference>
that writes to
<externalLink>
<linkText>NLog</linkText>
<linkUri>http://nlog-project.org/</linkUri>
<linkTarget>_blank</linkTarget>
</externalLink>.</para>
</introduction>
<section>
<title>Example</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\CustomTraceWriter.cs" region="Types" title="Types" />
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\CustomTraceWriter.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="DataContractAndDataMember" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This example shows how .NET Framework attributes such as
<codeEntityReference>T:System.Runtime.Serialization.DataContractAttribute</codeEntityReference>,
<codeEntityReference>T:System.Runtime.Serialization.DataMemberAttribute</codeEntityReference> and
<codeEntityReference>T:System.Runtime.Serialization.NonSerializedAttribute</codeEntityReference>
can be used with Json.NET instead of Json.NET's own attributes.</para>
</introduction>
<section>
<title>Example</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\CustomContractResolver.cs" region="Types" title="Types" />
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\CustomContractResolver.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="DefaultValueAttributeIgnore" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This example uses the <codeEntityReference>T:System.ComponentModel.DefaultValueAttribute</codeEntityReference>
to override the default value for a property and exclude it from serialization using
<codeEntityReference>T:Newtonsoft.Json.DefaultValueHandling</codeEntityReference>.</para>
</introduction>
<section>
<title>Example</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\DefaultValueAttributeIgnore.cs" region="Types" title="Types" />
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\DefaultValueAttributeIgnore.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="DefaultValueHandlingIgnore" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This example uses the <codeEntityReference>T:Newtonsoft.Json.DefaultValueHandling</codeEntityReference> setting to
not serialize properties with a default value.</para>
</introduction>
<section>
<title>Example</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\DefaultValueHandlingIgnore.cs" region="Types" title="Types" />
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\DefaultValueHandlingIgnore.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="DeserializeAnonymousType" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This example deserializes JSON into an anonymous type.</para>
</introduction>
<section>
<title>Example</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\DeserializeAnonymousType.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="DeserializeCollection" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This example deserializes JSON into a collection.</para>
</introduction>
<section>
<title>Example</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\DeserializeCollection.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="DeserializeConstructorHandling" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This example uses the <codeEntityReference>T:Newtonsoft.Json.ConstructorHandling</codeEntityReference> setting to
successfully deserialize the class using its non-public constructor.</para>
</introduction>
<section>
<title>Example</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\DeserializeConstructorHandling.cs" region="Types" title="Types" />
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\DeserializeConstructorHandling.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="DeserializeCustomCreationConverter" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This example creates a class that inherits from <codeEntityReference>T:Newtonsoft.Json.CustomCreationConverter`1</codeEntityReference>
that instantiates Employee instances for the Person type.</para>
</introduction>
<section>
<title>Example</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\DeserializeCustomCreationConverter.cs" region="Types" title="Types" />
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\DeserializeCustomCreationConverter.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="DeserializeDataSet" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This example deserializes JSON to a <codeEntityReference>T:System.Data.DataSet</codeEntityReference>.</para>
</introduction>
<section>
<title>Example</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\DeserializeDataSet.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="DeserializeDictionary" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This example deserializes JSON into a dictionary.</para>
</introduction>
<section>
<title>Example</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\DeserializeDictionary.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="DeserializeMissingMemberHandling" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This example attempts to deserialize JSON with <codeEntityReference>T:Newtonsoft.Json.MissingMemberHandling</codeEntityReference>
set to error and a JSON property that doesn't match to a member, causing an exception.</para>
</introduction>
<section>
<title>Example</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\DeserializeMissingMemberHandling.cs" region="Types" title="Types" />
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\DeserializeMissingMemberHandling.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="DeserializeObject" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This example deserializes JSON to an object.</para>
</introduction>
<section>
<title>Example</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\DeserializeObject.cs" region="Types" title="Types" />
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\DeserializeObject.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="DeserializeObjectCreationHandling" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This example deserializes JSON with <codeEntityReference>T:Newtonsoft.Json.ObjectCreationHandling</codeEntityReference>
set to Replace so that collection values aren't duplicated.</para>
</introduction>
<section>
<title>Example</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\DeserializeObjectCreationHandling.cs" region="Types" title="Types" />
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\DeserializeObjectCreationHandling.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="DeserializeWithJsonSerializerFromFile" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This example deserializes JSON retrieved from a file.</para>
</introduction>
<section>
<title>Example</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\DeserializeWithJsonSerializerFromFile.cs" region="Types" title="Types" />
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\DeserializeWithJsonSerializerFromFile.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="ErrorHandlingAttribute" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This example uses <codeEntityReference>T:Newtonsoft.Json.OnErrorAttribute</codeEntityReference> to ignore the exception thrown setting the Roles property.</para>
</introduction>
<section>
<title>Example</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\ErrorHandlingAttribute.cs" region="Types" title="Types" />
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\ErrorHandlingAttribute.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="ErrorHandlingEvent" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This example uses the <codeEntityReference>P:Newtonsoft.Json.JsonSerializerSettings.Error</codeEntityReference> event
to ignore the exceptions thrown from the invalid date strings.</para>
</introduction>
<section>
<title>Example</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\ErrorHandlingEvent.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="JsonConverterAttributeClass" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This example uses the
<codeEntityReference>T:Newtonsoft.Json.JsonConverterAttribute</codeEntityReference>
to specify that a <codeEntityReference>T:Newtonsoft.Json.JsonConverter</codeEntityReference>
should be used when serializing and deserializing a class.</para>
</introduction>
<section>
<title>Example</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\JsonConverterAttributeClass.cs" region="Types" title="Types" />
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\JsonConverterAttributeClass.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="JsonConverterAttributeProperty" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This example uses the
<codeEntityReference>T:Newtonsoft.Json.JsonConverterAttribute</codeEntityReference>
to specify that a <codeEntityReference>T:Newtonsoft.Json.JsonConverter</codeEntityReference>
should be used when serializing and deserializing a property.</para>
</introduction>
<section>
<title>Example</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\JsonConverterAttributeProperty.cs" region="Types" title="Types" />
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\JsonConverterAttributeProperty.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="JsonObjectAttributeOptIn" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This example uses
<codeEntityReference>T:Newtonsoft.Json.JsonObjectAttribute</codeEntityReference>
and <codeEntityReference>T:Newtonsoft.Json.MemberSerialization</codeEntityReference> to specify that
only properties that have been explicitly specified with <codeEntityReference>T:Newtonsoft.Json.JsonPropertyAttribute</codeEntityReference>
should be serialized.</para>
</introduction>
<section>
<title>Example</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\JsonObjectAttributeOptIn.cs" region="Types" title="Types" />
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\JsonObjectAttributeOptIn.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="JsonObjectAttributeOverrideIEnumerable" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This example uses <codeEntityReference>T:Newtonsoft.Json.JsonObjectAttribute</codeEntityReference>
to serialize a class that implements <codeEntityReference>T:System.IEnumerable`1</codeEntityReference> as
a JSON object instead of a JSON array.</para>
</introduction>
<section>
<title>Example</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\JsonObjectAttributeOverrideIEnumerable.cs" region="Types" title="Types" />
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\JsonObjectAttributeOverrideIEnumerable.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="JsonPropertyItemLevelSetting" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This example uses <codeEntityReference>T:Newtonsoft.Json.JsonPropertyAttribute</codeEntityReference>
to change how the property value's items are serialized,
e.g. setting ItemIsReference to true on a property with a collection will serialize all the collection's items
with reference tracking enabled.</para>
</introduction>
<section>
<title>Example</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\JsonPropertyItemLevelSetting.cs" region="Types" title="Types" />
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\JsonPropertyItemLevelSetting.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="JsonPropertyName" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This example uses <codeEntityReference>T:Newtonsoft.Json.JsonPropertyAttribute</codeEntityReference>
to change the names of properties when they are serialized to JSON.</para>
</introduction>
<section>
<title>Example</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\JsonPropertyName.cs" region="Types" title="Types" />
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\JsonPropertyName.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="JsonPropertyOrder" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This example uses <codeEntityReference>T:Newtonsoft.Json.JsonPropertyAttribute</codeEntityReference>
to order of properties when they are serialized to JSON.</para>
</introduction>
<section>
<title>Example</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\JsonPropertyOrder.cs" region="Types" title="Types" />
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\JsonPropertyOrder.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="JsonPropertyPropertyLevelSetting" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This example uses <codeEntityReference>T:Newtonsoft.Json.JsonPropertyAttribute</codeEntityReference>
to change how the property value is serialized.</para>
</introduction>
<section>
<title>Example</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\JsonPropertyPropertyLevelSetting.cs" region="Types" title="Types" />
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\JsonPropertyPropertyLevelSetting.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="JsonPropertyRequired" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This example uses <codeEntityReference>T:Newtonsoft.Json.JsonPropertyAttribute</codeEntityReference>
to set <codeEntityReference>T:Newtonsoft.Json.Required</codeEntityReference> which is used during deserialization
to validate the presence of required JSON properties.</para>
</introduction>
<section>
<title>Example</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\JsonPropertyRequired.cs" region="Types" title="Types" />
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\JsonPropertyRequired.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>
+15
View File
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="MaxDepth" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This example uses the <codeEntityReference>P:Newtonsoft.Json.JsonSerializerSettings.MaxDepth</codeEntityReference> setting to constrain JSON
to a maximum depth when deserializing.</para>
</introduction>
<section>
<title>Example</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\MaxDepth.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="NullValueHandlingIgnore" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This example serializes an object to JSON with <codeEntityReference>T:Newtonsoft.Json.NullValueHandling</codeEntityReference>
set to Ignore so that properties with a default value aren't included in the JSON result.</para>
</introduction>
<section>
<title>Example</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\NullValueHandlingIgnore.cs" region="Types" title="Types" />
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\NullValueHandlingIgnore.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="PopulateObject" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This example populates an existing object instance with values from JSON.</para>
</introduction>
<section>
<title>Example</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\PopulateObject.cs" region="Types" title="Types" />
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\PopulateObject.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="PreserveReferencesHandlingObject" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This example shows how the <codeEntityReference>T:Newtonsoft.Json.PreserveReferencesHandling</codeEntityReference>
setting can be used to serialize values by reference instead of by value.</para>
</introduction>
<section>
<title>Example</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\PreserveReferencesHandlingObject.cs" region="Types" title="Types" />
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\PreserveReferencesHandlingObject.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="PropertyJsonIgnore" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This example uses the <codeEntityReference>T:Newtonsoft.Json.JsonIgnoreAttribute</codeEntityReference>
to exclude a property from serialization.</para>
</introduction>
<section>
<title>Example</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\PropertyJsonIgnore.cs" region="Types" title="Types" />
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\PropertyJsonIgnore.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="ReferenceLoopHandlingIgnore" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This example sets <codeEntityReference>T:Newtonsoft.Json.ReferenceLoopHandling</codeEntityReference>
to Ignore so that looping values are excluded from serialization instead of throwing an exception.</para>
</introduction>
<section>
<title>Example</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\ReferenceLoopHandlingIgnore.cs" region="Types" title="Types" />
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\ReferenceLoopHandlingIgnore.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="SerializationCallbackAttributes" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This example uses serialization callback attributes
(<codeEntityReference>T:System.Runtime.Serialization.OnSerializingAttribute</codeEntityReference>,
<codeEntityReference>T:System.Runtime.Serialization.OnSerializedAttribute</codeEntityReference>,
<codeEntityReference>T:System.Runtime.Serialization.OnDeserializingAttribute</codeEntityReference>,
<codeEntityReference>T:System.Runtime.Serialization.OnDeserializedAttribute</codeEntityReference>)
to manipulate an object before and after its serialization and deserialization.</para>
</introduction>
<section>
<title>Example</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\SerializationCallbackAttributes.cs" region="Types" title="Types" />
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\SerializationCallbackAttributes.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="SerializeCollection" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This example serializes a collection to JSON.</para>
</introduction>
<section>
<title>Example</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\SerializeCollection.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="SerializeConditionalProperty" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This example uses a conditional property to exclude a property from serialization.</para>
</introduction>
<section>
<title>Example</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\SerializeConditionalProperty.cs" region="Types" title="Types" />
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\SerializeConditionalProperty.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="SerializeContractResolver" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This example uses a custom <codeEntityReference>T:Newtonsoft.Json.Serialization.IContractResolver</codeEntityReference>
to modify how objects are serialized.</para>
</introduction>
<section>
<title>Example</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\SerializeContractResolver.cs" region="Types" title="Types" />
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\SerializeContractResolver.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="SerializeDataSet" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This example serializes a DataSet to JSON.</para>
</introduction>
<section>
<title>Example</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\SerializeDataSet.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="SerializeDateFormatHandling" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This example uses the <codeEntityReference>T:Newtonsoft.Json.DateFormatHandling</codeEntityReference>
setting to control how <codeEntityReference>T:System.DateTime</codeEntityReference> and <codeEntityReference>T:System.DateTimeOffset</codeEntityReference> are serialized.</para>
</introduction>
<section>
<title>Example</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\SerializeDateFormatHandling.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="SerializeDateTimeZoneHandling" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This example uses the <codeEntityReference>T:Newtonsoft.Json.DateTimeZoneHandling</codeEntityReference>
setting to control how <codeEntityReference>T:System.DateTime</codeEntityReference> and <codeEntityReference>T:System.DateTimeOffset</codeEntityReference> are serialized.</para>
</introduction>
<section>
<title>Example</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\SerializeDateTimeZoneHandling.cs" region="Types" title="Types" />
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\SerializeDateTimeZoneHandling.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="SerializeDictionary" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This example serializes a dictionary to JSON.</para>
</introduction>
<section>
<title>Example</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\SerializeDictionary.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="SerializeObject" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This example serializes an object to JSON.</para>
</introduction>
<section>
<title>Example</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\SerializeObject.cs" region="Types" title="Types" />
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\SerializeObject.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="SerializeRawJson" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This example uses <codeEntityReference>T:Newtonsoft.Json.Linq.JRaw</codeEntityReference>
properties to serialize raw text to JSON.</para>
</introduction>
<section>
<title>Example</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\SerializeRawJson.cs" region="Types" title="Types" />
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\SerializeRawJson.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="SerializeSerializationBinder" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This example creates a custom <codeEntityReference>T:System.RunTime.Serialization.SerializationBinder</codeEntityReference>
that writes only the type name when including type data in JSON.</para>
</introduction>
<section>
<title>Example</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\SerializeSerializationBinder.cs" region="Types" title="Types" />
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\SerializeSerializationBinder.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="SerializeTypeNameHandling" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This example uses the <codeEntityReference>T:Newtonsoft.Json.TypeNameHandling</codeEntityReference>
setting to include type information when serializing JSON and read type information so that the create types are created when deserializing JSON.</para>
</introduction>
<section>
<title>Example</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\SerializeTypeNameHandling.cs" region="Types" title="Types" />
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\SerializeTypeNameHandling.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="SerializeUnindentedJson" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This example serializes an object to JSON without any formatting or indentation whitespace.</para>
</introduction>
<section>
<title>Example</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\SerializeUnindentedJson.cs" region="Types" title="Types" />
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\SerializeUnindentedJson.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="SerializeWithJsonConverters" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This example uses a <codeEntityReference>T:Newtonsoft.Json.JsonConverter</codeEntityReference>
to customize how JSON is serialized.</para>
</introduction>
<section>
<title>Example</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\SerializeWithJsonConverters.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="SerializeWithJsonSerializerToFile" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This example serializes JSON to a file.</para>
</introduction>
<section>
<title>Example</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\SerializeWithJsonSerializerToFile.cs" region="Types" title="Types" />
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\SerializeWithJsonSerializerToFile.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>
+16
View File
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="TraceWriter" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This example uses an <codeEntityReference>T:Newtonsoft.Json.Serialization.ITraceWriter</codeEntityReference>
to log debug information from serialization.</para>
</introduction>
<section>
<title>Example</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\TraceWriter.cs" region="Types" title="Types" />
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Examples\Serializer\TraceWriter.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>
+55 -2
View File
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Topics>
<Topic id="Introduction" visible="True" isDefault="true" />
<Topic id="SerializingJSON" visible="True" isExpanded="true" title="Serializing and Deserializing JSON">
<Topic id="SerializingJSON" visible="True" title="Serializing and Deserializing JSON">
<Topic id="SerializationSettings" visible="True" title="Serialization Settings" />
<Topic id="SerializationGuide" visible="True" title="Serialization Guide" />
<Topic id="SerializationAttributes" visible="True" title="Serialization Attributes" />
@@ -15,7 +15,7 @@
<Topic id="SerializingJSONFragments" visible="True" title="Serializing Partial JSON Fragments" />
<Topic id="ConditionalProperties" visible="True" title="Conditional Property Serialization" />
<Topic id="ContractResolver" visible="True" title="Serialization using ContractResolver" />
<Topic id="SerializationTracing" visible="True" isSelected="true" title="Debugging with Serialization Tracing" />
<Topic id="SerializationTracing" visible="True" title="Debugging with Serialization Tracing" />
</Topic>
<Topic id="LINQtoJSON" visible="True" title="LINQ to JSON">
<Topic id="ParsingLINQtoJSON" visible="True" title="Parsing JSON" />
@@ -29,4 +29,57 @@
<Topic id="ConvertingJSONandXML" visible="True" title="Converting between JSON and XML" />
<Topic id="JsonNetVsDotNetSerializers" visible="True" title="Json.NET vs .NET Serializers" />
<Topic id="JsonNetVsWindowsDataJson" visible="True" title="Json.NET vs Windows.Data.Json" />
<Topic id="Examples" visible="True" isExpanded="true">
<Topic id="Serializer" visible="True" isExpanded="true">
<Topic id="CustomContractResolver" visible="True" title="Custom Contract Resolver" />
<Topic id="CustomJsonConverter" visible="True" />
<Topic id="CustomTraceWriter" visible="True" />
<Topic id="DataContractAndDataMember" visible="True" />
<Topic id="DefaultValueAttributeIgnore" visible="True" />
<Topic id="DefaultValueHandlingIgnore" visible="True" />
<Topic id="DeserializeAnonymousType" visible="True" />
<Topic id="DeserializeCollection" visible="True" />
<Topic id="DeserializeConstructorHandling" visible="True" />
<Topic id="DeserializeCustomCreationConverter" visible="True" />
<Topic id="DeserializeDataSet" visible="True" />
<Topic id="DeserializeDictionary" visible="True" />
<Topic id="DeserializeMissingMemberHandling" visible="True" />
<Topic id="DeserializeObject" visible="True" />
<Topic id="DeserializeObjectCreationHandling" visible="True" isSelected="true" />
<Topic id="DeserializeWithJsonSerializerFromFile" visible="True" />
<Topic id="ErrorHandlingAttribute" visible="True" />
<Topic id="ErrorHandlingEvent" visible="True" />
<Topic id="JsonConverterAttributeClass" visible="True" />
<Topic id="JsonConverterAttributeProperty" visible="True" />
<Topic id="JsonObjectAttributeOptIn" visible="True" />
<Topic id="JsonObjectAttributeOverrideIEnumerable" visible="True" />
<Topic id="JsonPropertyItemLevelSetting" visible="True" />
<Topic id="JsonPropertyName" visible="True" />
<Topic id="JsonPropertyOrder" visible="True" />
<Topic id="JsonPropertyPropertyLevelSetting" visible="True" />
<Topic id="JsonPropertyRequired" visible="True" />
<Topic id="MaxDepth" visible="True" />
<Topic id="NullValueHandlingIgnore" visible="True" />
<Topic id="PopulateObject" visible="True" />
<Topic id="PreserveReferencesHandlingObject" visible="True" />
<Topic id="PropertyJsonIgnore" visible="True" />
<Topic id="ReferenceLoopHandlingIgnore" visible="True" />
<Topic id="SerializationCallbackAttributes" visible="True" />
<Topic id="SerializeCollection" visible="True" />
<Topic id="SerializeConditionalProperty" visible="True" />
<Topic id="SerializeContractResolver" visible="True" />
<Topic id="SerializeDataSet" visible="True" />
<Topic id="SerializeDateFormatHandling" visible="True" />
<Topic id="SerializeDateTimeZoneHandling" visible="True" />
<Topic id="SerializeDictionary" visible="True" />
<Topic id="SerializeObject" visible="True" />
<Topic id="SerializeRawJson" visible="True" />
<Topic id="SerializeSerializationBinder" visible="True" />
<Topic id="SerializeTypeNameHandling" visible="True" />
<Topic id="SerializeUnindentedJson" visible="True" />
<Topic id="SerializeWithJsonConverters" visible="True" />
<Topic id="SerializeWithJsonSerializerToFile" visible="True" />
<Topic id="TraceWriter" visible="True" />
</Topic>
</Topic>
</Topics>
+55
View File
@@ -137,6 +137,57 @@
<Content Include="donate.gif" />
</ItemGroup>
<ItemGroup>
<None Include="Examples\Serializer\TraceWriter.aml" />
<None Include="Examples\Serializer\SerializeWithJsonSerializerToFile.aml" />
<None Include="Examples\Serializer\SerializeWithJsonConverters.aml" />
<None Include="Examples\Serializer\SerializeUnindentedJson.aml" />
<None Include="Examples\Serializer\SerializeTypeNameHandling.aml" />
<None Include="Examples\Serializer\SerializeSerializationBinder.aml" />
<None Include="Examples\Serializer\SerializeRawJson.aml" />
<None Include="Examples\Serializer\SerializeObject.aml" />
<None Include="Examples\Serializer\SerializeDictionary.aml" />
<None Include="Examples\Serializer\SerializeDateTimeZoneHandling.aml" />
<None Include="Examples\Serializer\SerializeDateFormatHandling.aml" />
<None Include="Examples\Serializer\SerializeDataSet.aml" />
<None Include="Examples\Serializer\SerializeContractResolver.aml" />
<None Include="Examples\Serializer\SerializeConditionalProperty.aml" />
<None Include="Examples\Serializer\SerializeCollection.aml" />
<None Include="Examples\Serializer\SerializationCallbackAttributes.aml" />
<None Include="Examples\Serializer\ReferenceLoopHandlingIgnore.aml" />
<None Include="Examples\Serializer\PropertyJsonIgnore.aml" />
<None Include="Examples\Serializer\PreserveReferencesHandlingObject.aml" />
<None Include="Examples\Serializer\PopulateObject.aml" />
<None Include="Examples\Serializer\NullValueHandlingIgnore.aml" />
<None Include="Examples\Serializer\MaxDepth.aml" />
<None Include="Examples\Serializer\JsonPropertyRequired.aml" />
<None Include="Examples\Serializer\JsonPropertyPropertyLevelSetting.aml" />
<None Include="Examples\Serializer\JsonPropertyOrder.aml" />
<None Include="Examples\Serializer\JsonPropertyName.aml" />
<None Include="Examples\Serializer\JsonPropertyItemLevelSetting.aml" />
<None Include="Examples\Serializer\JsonObjectAttributeOverrideIEnumerable.aml" />
<None Include="Examples\Serializer\JsonObjectAttributeOptIn.aml" />
<None Include="Examples\Serializer\JsonConverterAttributeProperty.aml" />
<None Include="Examples\Serializer\JsonConverterAttributeClass.aml" />
<None Include="Examples\Serializer\ErrorHandlingEvent.aml" />
<None Include="Examples\Serializer\ErrorHandlingAttribute.aml" />
<None Include="Examples\Serializer\DeserializeWithJsonSerializerFromFile.aml" />
<None Include="Examples\Serializer\DeserializeObjectCreationHandling.aml" />
<None Include="Examples\Serializer\DeserializeObject.aml" />
<None Include="Examples\Serializer\DeserializeMissingMemberHandling.aml" />
<None Include="Examples\Serializer\DeserializeDictionary.aml" />
<None Include="Examples\Serializer\DeserializeDataSet.aml" />
<None Include="Examples\Serializer\DeserializeCustomCreationConverter.aml" />
<None Include="Examples\Serializer\DeserializeConstructorHandling.aml" />
<None Include="Examples\Serializer\DeserializeCollection.aml" />
<None Include="Examples\Serializer\DeserializeAnonymousType.aml" />
<None Include="Examples\Serializer\DefaultValueHandlingIgnore.aml" />
<None Include="Examples\Serializer\DefaultValueAttributeIgnore.aml" />
<None Include="Examples\Serializer\DataContractAndDataMember.aml" />
<None Include="Examples\Serializer\CustomTraceWriter.aml" />
<None Include="Examples\Serializer\CustomJsonConverter.aml" />
<None Include="Examples\Serializer\CustomContractResolver.aml" />
<None Include="Examples\Serializer.aml" />
<None Include="Examples\Examples.aml" />
<None Include="SerializationTracing.aml" />
<None Include="JsonNetVsDotNetSerializers.aml" />
<None Include="JsonNetVsWindowsDataJson.aml" />
@@ -191,6 +242,10 @@
<AlternateText>logo</AlternateText>
</Image>
</ItemGroup>
<ItemGroup>
<Folder Include="Examples\Serializer\" />
<Folder Include="Examples\" />
</ItemGroup>
<!-- Import the SHFB build targets -->
<Import Project="$(SHFBROOT)\SandcastleHelpFileBuilder.targets" />
</Project>
@@ -22,14 +22,14 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
{
string json = @"[
{
""Title"": ""Json.NET is awesome!"",
""Author"": {
""Name"": ""James Newton-King"",
""Twitter"": ""@JamesNK"",
""Picture"": ""/jamesnk.png""
'Title': 'Json.NET is awesome!',
'Author': {
'Name': 'James Newton-King',
'Twitter': '@JamesNK',
'Picture': '/jamesnk.png'
},
""Date"": ""2013-01-23T19:30:00"",
""BodyHtml"": ""&lt;h3&gt;Title!&lt;/h3&gt;\r\n&lt;p&gt;Content!&lt;/p&gt;""
'Date': '2013-01-23T19:30:00',
'BodyHtml': '&lt;h3&gt;Title!&lt;/h3&gt;\r\n&lt;p&gt;Content!&lt;/p&gt;'
}
]";
@@ -11,12 +11,12 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
public void Example()
{
string json = @"{
""channel"": {
""title"": ""Star Wars"",
""link"": ""http://www.starwars.com"",
""description"": ""Star Wars blog."",
""obsolete"": ""Obsolete value"",
""item"": []
'channel': {
'title': 'Star Wars',
'link': 'http://www.starwars.com',
'description': 'Star Wars blog.',
'obsolete': 'Obsolete value',
'item': []
}
}";
@@ -25,7 +25,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
Console.WriteLine(t3.Type);
// Null
JToken t4 = JToken.Parse(@"""A string!""");
JToken t4 = JToken.Parse(@"'A string!'");
Console.WriteLine(t4.Type);
// String
@@ -13,14 +13,14 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
{
string json = @"[
{
""Title"": ""Json.NET is awesome!"",
""Author"": {
""Name"": ""James Newton-King"",
""Twitter"": ""@JamesNK"",
""Picture"": ""/jamesnk.png""
'Title': 'Json.NET is awesome!',
'Author': {
'Name': 'James Newton-King',
'Twitter': '@JamesNK',
'Picture': '/jamesnk.png'
},
""Date"": ""2013-01-23T19:30:00"",
""BodyHtml"": ""&lt;h3&gt;Title!&lt;/h3&gt;\r\n&lt;p&gt;Content!&lt;/p&gt;""
'Date': '2013-01-23T19:30:00',
'BodyHtml': '&lt;h3&gt;Title!&lt;/h3&gt;\r\n&lt;p&gt;Content!&lt;/p&gt;'
}
]";
@@ -16,12 +16,12 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
public void Example()
{
string json = @"{
""d"": [
'd': [
{
""Name"": ""John Smith""
'Name': 'John Smith'
},
{
""Name"": ""Mike Smith""
'Name': 'Mike Smith'
}
]
}";
@@ -15,33 +15,33 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Schema
JsonSchemaResolver resolver = new JsonSchemaResolver();
schemaJson = @"{
""id"": ""person"",
""type"": ""object"",
""properties"": {
""name"": {""type"":""string""},
""age"": {""type"":""integer""}
'id': 'person',
'type': 'object',
'properties': {
'name': {'type':'string'},
'age': {'type':'integer'}
}
}";
JsonSchema personSchema = JsonSchema.Parse(schemaJson, resolver);
schemaJson = @"{
""id"": ""employee"",
""type"": ""object"",
""extends"": {""$ref"":""person""},
""properties"": {
""salary"": {""type"":""number""},
""jobTitle"": {""type"":""string""}
'id': 'employee',
'type': 'object',
'extends': {'$ref':'person'},
'properties': {
'salary': {'type':'number'},
'jobTitle': {'type':'string'}
}
}";
JsonSchema employeeSchema = JsonSchema.Parse(schemaJson, resolver);
string json = @"{
""name"": ""James"",
""age"": 29,
""salary"": 9000.01,
""jobTitle"": ""Junior Vice President""
'name': 'James',
'age': 29,
'salary': 9000.01,
'jobTitle': 'Junior Vice President'
}";
JObject employee = JObject.Parse(json);
@@ -8,6 +8,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
{
public class CustomContractResolver
{
#region Types
public class DynamicContractResolver : DefaultContractResolver
{
private readonly char _startingWithChar;
@@ -38,9 +39,11 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
get { return FirstName + " " + LastName; }
}
}
#endregion
public void Example()
{
#region Usage
Person person = new Person
{
FirstName = "Dennis",
@@ -63,6 +66,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
// {
// "LastName": "Deepwater-Diver"
// }
#endregion
}
}
}
@@ -8,6 +8,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
{
public class CustomJsonConverter
{
#region Types
public class KeysJsonConverter : JsonConverter
{
private Type[] _types;
@@ -58,9 +59,11 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
public string LastName { get; set; }
public IList<string> Roles { get; set; }
}
#endregion
public void Example()
{
#region Usage
Employee employee = new Employee
{
FirstName = "James",
@@ -91,6 +94,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
Console.WriteLine(newEmployee.FirstName);
// James
#endregion
}
}
}
@@ -9,6 +9,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
{
public class CustomTraceWriter
{
#region Types
public class NLogTraceWriter : ITraceWriter
{
private static readonly Logger Logger = LogManager.GetLogger("NLogTraceWriter");
@@ -49,9 +50,11 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
}
}
}
#endregion
public void Example()
{
#region Usage
IList<string> countries = new List<string>
{
"New Zealand",
@@ -72,6 +75,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
// "Denmark",
// "China"
// ]
#endregion
}
}
}
@@ -8,6 +8,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
{
public class DataContractAndDataMember
{
#region Usage
[DataContract]
public class File
{
@@ -20,9 +21,11 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
[DataMember]
public int Size { get; set; }
}
#endregion
public void Example()
{
#region Usage
File file = new File
{
Id = Guid.NewGuid(),
@@ -37,6 +40,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
// "Name": "ImportantLegalDocuments.docx",
// "Size": 51200
// }
#endregion
}
}
}
@@ -8,6 +8,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
{
public class DefaultValueAttributeIgnore
{
#region Types
public class Customer
{
public string FirstName { get; set; }
@@ -19,9 +20,11 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
get { return FirstName + " " + LastName; }
}
}
#endregion
public void Example()
{
#region Usage
Customer customer = new Customer();
string jsonIncludeDefaultValues = JsonConvert.SerializeObject(customer, Formatting.Indented);
@@ -40,6 +43,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
Console.WriteLine(jsonIgnoreDefaultValues);
// {}
#endregion
}
}
}
@@ -7,6 +7,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
{
public class DefaultValueHandlingIgnore
{
#region Types
public class Person
{
public string Name { get; set; }
@@ -14,9 +15,11 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
public Person Partner { get; set; }
public decimal? Salary { get; set; }
}
#endregion
public void Example()
{
#region Usage
Person person = new Person();
string jsonIncludeDefaultValues = JsonConvert.SerializeObject(person, Formatting.Indented);
@@ -36,6 +39,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
Console.WriteLine(jsonIgnoreDefaultValues);
// {}
#endregion
}
}
}
@@ -9,7 +9,8 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
{
public void Example()
{
string json = @"{""Name"":""James""}";
#region Usage
string json = @"{'Name':'James'}";
var customerDefinition = new {Name = ""};
@@ -17,6 +18,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
Console.WriteLine(customer.Name);
// James
#endregion
}
}
}
@@ -9,12 +9,14 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
{
public void Example()
{
string json = @"[""Starcraft"",""Halo"",""Legend of Zelda""]";
#region Usage
string json = @"['Starcraft','Halo','Legend of Zelda']";
List<string> videogames = JsonConvert.DeserializeObject<List<string>>(json);
Console.WriteLine(string.Join(", ", videogames));
// Starcraft, Halo, Legend of Zelda
#endregion
}
}
}
}
@@ -8,6 +8,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
{
public class DeserializeConstructorHandling
{
#region Types
public class Website
{
public string Url { get; set; }
@@ -24,10 +25,12 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
Url = website.Url;
}
}
#endregion
public void Example()
{
string json = @"{""Url"":""http://www.google.com""}";
#region Usage
string json = @"{'Url':'http://www.google.com'}";
try
{
@@ -46,6 +49,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
Console.WriteLine(website.Url);
// http://www.google.com
#endregion
}
}
}
@@ -8,6 +8,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
{
public class DeserializeCustomCreationConverter
{
#region Types
public class Person
{
public string FirstName { get; set; }
@@ -28,15 +29,17 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
return new Employee();
}
}
#endregion
public void Example()
{
#region Usage
string json = @"{
""Department"": ""Furniture"",
""JobTitle"": ""Carpenter"",
""FirstName"": ""John"",
""LastName"": ""Joinery"",
""BirthDate"": ""1983-02-02T00:00:00""
'Department': 'Furniture',
'JobTitle': 'Carpenter',
'FirstName': 'John',
'LastName': 'Joinery',
'BirthDate': '1983-02-02T00:00:00'
}";
Person person = JsonConvert.DeserializeObject<Person>(json, new PersonConverter());
@@ -48,6 +51,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
Console.WriteLine(employee.JobTitle);
// Capenter
#endregion
}
}
}
@@ -11,15 +11,16 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
{
public void Example()
{
#region Usage
string json = @"{
""Table1"": [
'Table1': [
{
""id"": 0,
""item"": ""item 0""
'id': 0,
'item': 'item 0'
},
{
""id"": 1,
""item"": ""item 1""
'id': 1,
'item': 'item 1'
}
]
}";
@@ -37,6 +38,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
}
// 0 - item 0
// 1 - item 1
#endregion
}
}
}
@@ -9,9 +9,10 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
{
public void Example()
{
#region Usage
string json = @"{
""href"": ""/account/login.aspx"",
""target"": ""_blank""
'href': '/account/login.aspx',
'target': '_blank'
}";
Dictionary<string, string> htmlAttributes = JsonConvert.DeserializeObject<Dictionary<string, string>>(json);
@@ -21,6 +22,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
Console.WriteLine(htmlAttributes["target"]);
// _blank
#endregion
}
}
}
@@ -7,18 +7,21 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
{
public class DeserializeMissingMemberHandling
{
#region Types
public class Account
{
public string FullName { get; set; }
public bool Deleted { get; set; }
}
#endregion
public void Example()
{
#region Usage
string json = @"{
""FullName"": ""Dan Deleted"",
""Deleted"": true,
""DeletedDate"": ""2013-01-20T00:00:00""
'FullName': 'Dan Deleted',
'Deleted': true,
'DeletedDate': '2013-01-20T00:00:00'
}";
try
@@ -28,10 +31,12 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
MissingMemberHandling = MissingMemberHandling.Error
});
}
catch (JsonSerializationException)
catch (JsonSerializationException ex)
{
Console.WriteLine(ex.Message);
// Could not find member 'DeletedDate' on object of type 'Account'. Path 'DeletedDate', line 4, position 23.
}
#endregion
}
}
}
@@ -7,6 +7,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
{
public class DeserializeObject
{
#region Types
public class Account
{
public string Email { get; set; }
@@ -14,16 +15,18 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
public DateTime CreatedDate { get; set; }
public IList<string> Roles { get; set; }
}
#endregion
public void Example()
{
#region Usage
string json = @"{
""Email"": ""james@example.com"",
""Active"": true,
""CreatedDate"": ""2013-01-20T00:00:00Z"",
""Roles"": [
""User"",
""Admin""
'Email': 'james@example.com',
'Active': true,
'CreatedDate': '2013-01-20T00:00:00Z',
'Roles': [
'User',
'Admin'
]
}";
@@ -31,6 +34,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
Console.WriteLine(account.Email);
// james@example.com
#endregion
}
}
}
@@ -7,6 +7,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
{
public class DeserializeObjectCreationHandling
{
#region Types
public class UserViewModel
{
public string Name { get; set; }
@@ -22,15 +23,17 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
};
}
}
#endregion
public void Example()
{
#region Usage
string json = @"{
""Name"": ""James"",
""Offices"": [
""Auckland"",
""Wellington"",
""Christchurch""
'Name': 'James',
'Offices': [
'Auckland',
'Wellington',
'Christchurch'
]
}";
@@ -59,6 +62,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
// Auckland
// Wellington
// Christchurch
#endregion
}
}
}
@@ -9,14 +9,17 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
{
public class DeserializeWithJsonSerializerFromFile
{
#region Types
public class Movie
{
public string Name { get; set; }
public int Year { get; set; }
}
#endregion
public void Example()
{
#region Usage
// read file into a string and deserialize JSON to a type
Movie movie1 = JsonConvert.DeserializeObject<Movie>(File.ReadAllText(@"c:\movie.json"));
@@ -26,6 +29,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
JsonSerializer serializer = new JsonSerializer();
Movie movie2 = (Movie)serializer.Deserialize(file, typeof (Movie));
}
#endregion
}
}
}
@@ -9,6 +9,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
{
public class ErrorHandlingAttribute
{
#region Types
public class Employee
{
private List<string> _roles;
@@ -34,9 +35,11 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
errorContext.Handled = true;
}
}
#endregion
public void Example()
{
#region Usage
Employee person = new Employee
{
Name = "George Michael Bluth",
@@ -53,6 +56,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
// "Age": 16,
// "Title": "Mister Manager"
// }
#endregion
}
}
}
@@ -11,6 +11,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
{
public void Example()
{
#region Usage
List<string> errors = new List<string>();
List<DateTime> c = JsonConvert.DeserializeObject<List<DateTime>>(@"[
@@ -40,6 +41,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
// The string was not recognized as a valid DateTime. There is a unknown word starting at index 0.
// Unexpected token parsing date. Expected String, got StartArray.
// Cannot convert null value to System.DateTime.
#endregion
}
}
}
@@ -8,6 +8,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
{
public class JsonConverterAttributeClass
{
#region Types
public class UserConverter : JsonConverter
{
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
@@ -36,9 +37,11 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
{
public string UserName { get; set; }
}
#endregion
public void Example()
{
#region Usage
User user = new User
{
UserName = @"domain\username"
@@ -48,6 +51,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
Console.WriteLine(json);
// "domain\\username"
#endregion
}
}
}
@@ -8,6 +8,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
{
public class JsonConverterAttributeProperty
{
#region Types
public enum UserStatus
{
NotConfirmed,
@@ -22,9 +23,11 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
[JsonConverter(typeof(StringEnumConverter))]
public UserStatus Status { get; set; }
}
#endregion
public void Example()
{
#region Usage
User user = new User
{
UserName = @"domain\username",
@@ -38,6 +41,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
// "UserName": "domain\\username",
// "Status": "Deleted"
// }
#endregion
}
}
}
@@ -7,6 +7,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
{
public class JsonObjectAttributeOptIn
{
#region Types
[JsonObject(MemberSerialization.OptIn)]
public class File
{
@@ -19,9 +20,11 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
[JsonProperty]
public int Size { get; set; }
}
#endregion
public void Example()
{
#region Usage
File file = new File
{
Id = Guid.NewGuid(),
@@ -36,6 +39,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
// "Name": "ImportantLegalDocuments.docx",
// "Size": 51200
// }
#endregion
}
}
}
@@ -8,6 +8,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
{
public class JsonObjectAttributeOverrideIEnumerable
{
#region Types
[JsonObject]
public class Directory : IEnumerable<string>
{
@@ -29,9 +30,11 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
return GetEnumerator();
}
}
#endregion
public void Example()
{
#region Usage
Directory directory = new Directory
{
Name = "My Documents",
@@ -52,6 +55,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
// "WiseFinancalAdvice.xlsx"
// ]
// }
#endregion
}
}
}
@@ -7,6 +7,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
{
public class JsonPropertyItemLevelSetting
{
#region Types
public class Business
{
public string Name { get; set; }
@@ -22,9 +23,11 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
[JsonProperty(IsReference = true)]
public Employee Manager { get; set; }
}
#endregion
public void Example()
{
#region Usage
Employee manager = new Employee
{
Name = "George-Michael"
@@ -65,6 +68,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
// }
// ]
// }
#endregion
}
}
}
@@ -7,6 +7,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
{
public class JsonPropertyName
{
#region Types
public class Videogame
{
[JsonProperty("name")]
@@ -15,9 +16,11 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
[JsonProperty("release_date")]
public DateTime ReleaseDate { get; set; }
}
#endregion
public void Example()
{
#region Usage
Videogame starcraft = new Videogame
{
Name = "Starcraft",
@@ -31,6 +34,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
// "name": "Starcraft",
// "release_date": "1998-01-01T00:00:00"
// }
#endregion
}
}
}
@@ -7,6 +7,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
{
public class JsonPropertyOrder
{
#region Types
public class Account
{
public string EmailAddress { get; set; }
@@ -24,9 +25,11 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
[JsonProperty(Order = -2)]
public string FullName { get; set; }
}
#endregion
public void Example()
{
#region Usage
Account account = new Account
{
FullName = "Aaron Account",
@@ -48,6 +51,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
// "Deleted": true,
// "DeletedDate": "2013-01-25T00:00:00"
// }
#endregion
}
}
}
}
@@ -7,6 +7,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
{
public class JsonPropertyPropertyLevelSetting
{
#region Types
public class Vessel
{
public string Name { get; set; }
@@ -15,9 +16,11 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public DateTime? LaunchDate { get; set; }
}
#endregion
public void Example()
{
#region Usage
Vessel vessel = new Vessel
{
Name = "Red October",
@@ -31,6 +34,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
// "Name": "Red October",
// "Class": "Typhoon"
// }
#endregion
}
}
}
@@ -7,6 +7,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
{
public class JsonPropertyRequired
{
#region Types
public class Videogame
{
[JsonProperty(Required = Required.Always)]
@@ -15,12 +16,14 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
[JsonProperty(Required = Required.AllowNull)]
public DateTime? ReleaseDate { get; set; }
}
#endregion
public void Example()
{
#region Usage
string json = @"{
""Name"": ""Starcraft III"",
""ReleaseDate"": null
'Name': 'Starcraft III',
'ReleaseDate': null
}";
Videogame starcraft = JsonConvert.DeserializeObject<Videogame>(json);
@@ -30,6 +33,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
Console.WriteLine(starcraft.ReleaseDate);
// null
#endregion
}
}
}
@@ -9,12 +9,13 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
{
public void Example()
{
#region Usage
string json = @"[
[
[
""1"",
""Two"",
""III""
'1',
'Two',
'III'
]
]
]";
@@ -31,6 +32,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
Console.WriteLine(ex.Message);
// The reader's MaxDepth of 2 has been exceeded. Path '[0][0]', line 3, position 12.
}
#endregion
}
}
}
@@ -7,6 +7,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
{
public class NullValueHandlingIgnore
{
#region Types
public class Person
{
public string Name { get; set; }
@@ -14,9 +15,11 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
public Person Partner { get; set; }
public decimal? Salary { get; set; }
}
#endregion
public void Example()
{
#region Usage
Person person = new Person
{
Name = "Nigal Newborn",
@@ -43,6 +46,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
// "Name": "Nigal Newborn",
// "Age": 1
// }
#endregion
}
}
}
@@ -7,6 +7,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
{
public class PopulateObject
{
#region Types
public class Account
{
public string Email { get; set; }
@@ -14,9 +15,11 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
public DateTime CreatedDate { get; set; }
public IList<string> Roles { get; set; }
}
#endregion
public void Example()
{
#region Usage
Account account = new Account
{
Email = "james@example.com",
@@ -30,9 +33,9 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
};
string json = @"{
""Active"": false,
""Roles"": [
""Expired""
'Active': false,
'Roles': [
'Expired'
]
}";
@@ -46,6 +49,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
Console.WriteLine(string.Join(", ", account.Roles));
// User, Admin, Expired
#endregion
}
}
}
@@ -5,8 +5,9 @@ using System.Text;
namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
{
public class ReferenceLoopHandlingObject
public class PreserveReferencesHandlingObject
{
#region Types
public class Directory
{
public string Name { get; set; }
@@ -19,9 +20,11 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
public string Name { get; set; }
public Directory Parent { get; set; }
}
#endregion
public void Example()
{
#region Usage
Directory root = new Directory { Name = "Root" };
Directory documents = new Directory { Name = "My Documents", Parent = root };
@@ -93,6 +96,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
// }
// ]
// }
#endregion
}
}
}
@@ -7,6 +7,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
{
public class PropertyJsonIgnore
{
#region Types
public class Account
{
public string FullName { get; set; }
@@ -14,9 +15,11 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
[JsonIgnore]
public string PasswordHash { get; set; }
}
#endregion
public void Example()
{
#region Usage
Account account = new Account
{
FullName = "Joe User",
@@ -28,6 +31,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
Console.WriteLine(json);
// {"FullName":"Joe User","EmailAddress":"joe@example.com"}
#endregion
}
}
}
@@ -7,14 +7,17 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
{
public class ReferenceLoopHandlingIgnore
{
#region Types
public class Employee
{
public string Name { get; set; }
public Employee Manager { get; set; }
}
#endregion
public void Example()
{
#region Usage
Employee joe = new Employee { Name = "Joe User" };
Employee mike = new Employee { Name = "Mike Manager" };
joe.Manager = mike;
@@ -32,6 +35,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
// "Name": "Mike Manager"
// }
// }
#endregion
}
}
}
@@ -8,6 +8,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
{
public class SerializationCallbackAttributes
{
#region Types
public class SerializationEventTestObject
{
// 2222
@@ -58,9 +59,11 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
Member4 = "This value was set after deserialization.";
}
}
#endregion
public void Example()
{
#region Usage
SerializationEventTestObject obj = new SerializationEventTestObject();
Console.WriteLine(obj.Member1);
@@ -98,6 +101,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
// This value was set during deserialization
Console.WriteLine(obj.Member4);
// This value was set after deserialization.
#endregion
}
}
}
@@ -9,6 +9,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
{
public void Example()
{
#region Usage
List<string> videogames = new List<string>
{
"Starcraft",
@@ -20,6 +21,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
Console.WriteLine(json);
// ["Starcraft","Halo","Legend of Zelda"]
#endregion
}
}
}
@@ -7,6 +7,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
{
public class SerializeConditionalProperty
{
#region Types
public class Employee
{
public string Name { get; set; }
@@ -18,9 +19,11 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
return (Manager != this);
}
}
#endregion
public void Example()
{
#region Usage
Employee joe = new Employee();
joe.Name = "Joe Employee";
Employee mike = new Employee();
@@ -33,6 +36,8 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
mike.Manager = mike;
string json = JsonConvert.SerializeObject(new[] { joe, mike }, Formatting.Indented);
Console.WriteLine(json);
// [
// {
// "Name": "Joe Employee",
@@ -44,6 +49,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
// "Name": "Mike Manager"
// }
// ]
#endregion
}
}
}
@@ -8,6 +8,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
{
public class SerializeContractResolver
{
#region Types
public class Person
{
public string FirstName { get; set; }
@@ -18,9 +19,11 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
get { return FirstName + " " + LastName; }
}
}
#endregion
public void Example()
{
#region Usage
Person person = new Person
{
FirstName = "Sarah",
@@ -38,6 +41,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
// "lastName": "Security",
// "fullName": "Sarah Security"
// }
#endregion
}
}
}
@@ -11,6 +11,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
{
public void Example()
{
#region Usage
DataSet dataSet = new DataSet("dataSet");
dataSet.Namespace = "NetFrameWork";
DataTable table = new DataTable();
@@ -46,6 +47,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
// }
// ]
// }
#endregion
}
}
}
@@ -9,6 +9,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
{
public void Example()
{
#region Usage
DateTime mayanEndOfTheWorld = new DateTime(2012, 12, 21);
string jsonIsoDate = JsonConvert.SerializeObject(mayanEndOfTheWorld);
@@ -23,6 +24,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
Console.WriteLine(jsonMsDate);
// "\/Date(1356044400000+0100)\/"
#endregion
}
}
}
@@ -7,6 +7,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
{
public class SerializeDateTimeZoneHandling
{
#region Types
public class Flight
{
public string Destination { get; set; }
@@ -15,9 +16,11 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
public DateTime DepartureDateLocal { get; set; }
public TimeSpan Duration { get; set; }
}
#endregion
public void Example()
{
#region Usage
Flight flight = new Flight
{
Destination = "Dubai",
@@ -82,6 +85,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
// "DepartureDateLocal": "2013-01-21T00:00:00",
// "Duration": "05:30:00"
// }
#endregion
}
}
}
}

Some files were not shown because too many files have changed in this diff Show More