Merge branch 'master' of github.com:JamesNK/Newtonsoft.Json
Conflicts: Src/Newtonsoft.Json/JsonWriter.cs
This commit is contained in:
+4
-1
@@ -4,4 +4,7 @@
|
|||||||
TestResults/
|
TestResults/
|
||||||
AppPackages/
|
AppPackages/
|
||||||
*.suo
|
*.suo
|
||||||
*.user
|
*.user
|
||||||
|
_ReSharper.*
|
||||||
|
*.ReSharper.user
|
||||||
|
*.resharper.user
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<topic id="ConditionalProperties" 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>M:Newtonsoft.Json.Serialization.JsonProperty.ShouldSerialize</codeEntityReference>
|
||||||
|
</relatedTopics>
|
||||||
|
</developerConceptualDocument>
|
||||||
|
</topic>
|
||||||
+70
-53
@@ -1,54 +1,71 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<topic id="ContractResolver" revisionNumber="1">
|
<topic id="ContractResolver" revisionNumber="1">
|
||||||
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
|
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||||
<!--
|
<!--
|
||||||
<summary>
|
<summary>
|
||||||
<para>Optional summary abstract</para>
|
<para>Optional summary abstract</para>
|
||||||
</summary>
|
</summary>
|
||||||
-->
|
-->
|
||||||
<introduction>
|
<introduction>
|
||||||
<para>The <codeEntityReference>T:Newtonsoft.Json.Serialization.IContractResolver</codeEntityReference>
|
<para>The <codeEntityReference>T:Newtonsoft.Json.Serialization.IContractResolver</codeEntityReference>
|
||||||
interface provides a way to customize how the
|
interface provides a way to customize how the
|
||||||
JsonSerializer serializes and deserializes .NET objects to JSON.</para>
|
JsonSerializer serializes and deserializes .NET objects to JSON.</para>
|
||||||
<para>Implementing the IContractResolver interface and then assigning an
|
<para>Implementing the IContractResolver interface and then assigning an
|
||||||
instance to a JsonSerializer lets you control whether the object is
|
instance to a JsonSerializer lets you control whether the object is
|
||||||
serialized as a JSON object or JSON array, what object members should be
|
serialized as a JSON object or JSON array, what object members should be
|
||||||
serialized, how they are serialized and what they are called.</para>
|
serialized, how they are serialized and what they are called.</para>
|
||||||
</introduction>
|
</introduction>
|
||||||
<!-- Add one or more top-level section elements. These are collapsible.
|
<!-- Add one or more top-level section elements. These are collapsible.
|
||||||
If using <autoOutline />, add an address attribute to identify it
|
If using <autoOutline />, add an address attribute to identify it
|
||||||
and specify a title so that it can be jumped to with a hyperlink. -->
|
and specify a title so that it can be jumped to with a hyperlink. -->
|
||||||
<section>
|
<section>
|
||||||
<title>DefaultContractResolver</title>
|
<title>DefaultContractResolver</title>
|
||||||
<content>
|
<content>
|
||||||
<!-- Uncomment this to create a sub-section outline
|
<!-- Uncomment this to create a sub-section outline
|
||||||
<autoOutline /> -->
|
<autoOutline /> -->
|
||||||
<para>The <codeEntityReference>T:Newtonsoft.Json.Serialization.DefaultContractResolver</codeEntityReference>
|
<para>The <codeEntityReference>T:Newtonsoft.Json.Serialization.DefaultContractResolver</codeEntityReference>
|
||||||
is the default resolver used by the
|
is the default resolver used by the
|
||||||
serializer. It provides many avenues of extensibility in the form of
|
serializer. It provides many avenues of extensibility in the form of
|
||||||
virtual methods that can be overriden.</para>
|
virtual methods that can be overriden.</para>
|
||||||
</content>
|
</content>
|
||||||
</section>
|
</section>
|
||||||
<section>
|
<section>
|
||||||
<title>CamelCasePropertyNamesContractResolver</title>
|
<title>CamelCasePropertyNamesContractResolver</title>
|
||||||
<content>
|
<content>
|
||||||
<!-- Uncomment this to create a sub-section outline
|
<!-- Uncomment this to create a sub-section outline
|
||||||
<autoOutline /> -->
|
<autoOutline /> -->
|
||||||
<para><codeEntityReference>T:Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver</codeEntityReference>
|
<para><codeEntityReference>T:Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver</codeEntityReference>
|
||||||
inherits from DefaultContractResolver and simply overrides the JSON
|
inherits from DefaultContractResolver and simply overrides the JSON
|
||||||
property name to be written in <externalLink>
|
property name to be written in <externalLink>
|
||||||
<linkText>camelcase</linkText>
|
<linkText>camelcase</linkText>
|
||||||
<linkUri>http://en.wikipedia.org/wiki/CamelCase</linkUri>
|
<linkUri>http://en.wikipedia.org/wiki/CamelCase</linkUri>
|
||||||
<linkTarget>_blank</linkTarget>
|
<linkTarget>_blank</linkTarget>
|
||||||
</externalLink>.</para>
|
</externalLink>.</para>
|
||||||
|
|
||||||
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\SerializationTests.cs" region="ContractResolver" title="ContractResolver" />
|
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\SerializationTests.cs" region="ContractResolver" title="ContractResolver" />
|
||||||
</content>
|
</content>
|
||||||
</section>
|
</section>
|
||||||
<relatedTopics>
|
<section>
|
||||||
<codeEntityReference>T:Newtonsoft.Json.Serialization.IContractResolver</codeEntityReference>
|
<title>Custom Examples</title>
|
||||||
<codeEntityReference>T:Newtonsoft.Json.Serialization.DefaultContractResolver</codeEntityReference>
|
<content>
|
||||||
<codeEntityReference>T:Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver</codeEntityReference>
|
<para>Setting a <codeEntityReference>T:Newtonsoft.Json.JsonConverter</codeEntityReference> on a type
|
||||||
</relatedTopics>
|
using an IContractResolver.</para>
|
||||||
</developerConceptualDocument>
|
|
||||||
|
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\PerformanceTests.cs" region="JsonConverterContractResolver" title="Use JsonConverter with IContractResolver" />
|
||||||
|
|
||||||
|
<para><externalLink>
|
||||||
|
<linkText>Conditionally serializing properties</linkText>
|
||||||
|
<linkUri>ConditionalProperties.htm</linkUri>
|
||||||
|
<linkTarget>_self</linkTarget>
|
||||||
|
</externalLink> using an IContractResolver.</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.Serialization.IContractResolver</codeEntityReference>
|
||||||
|
<codeEntityReference>T:Newtonsoft.Json.Serialization.DefaultContractResolver</codeEntityReference>
|
||||||
|
<codeEntityReference>T:Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver</codeEntityReference>
|
||||||
|
</relatedTopics>
|
||||||
|
</developerConceptualDocument>
|
||||||
</topic>
|
</topic>
|
||||||
@@ -0,0 +1,454 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<topic id="JsonNetVsDotNetSerializers" revisionNumber="1">
|
||||||
|
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||||
|
<introduction>
|
||||||
|
<para>Json.NET offers many features not found in the JavaScriptSerializer and DataContractSerializer that come with .NET.</para>
|
||||||
|
</introduction>
|
||||||
|
<section>
|
||||||
|
<title>Feature Comparison</title>
|
||||||
|
<content>
|
||||||
|
<table>
|
||||||
|
<tableHeader>
|
||||||
|
<row>
|
||||||
|
<entry><para></para></entry>
|
||||||
|
<entry><para>Json.NET</para></entry>
|
||||||
|
<entry><para>DataContractJsonSerializer</para></entry>
|
||||||
|
<entry><para>JavaScriptSerializer</para></entry>
|
||||||
|
</row>
|
||||||
|
</tableHeader>
|
||||||
|
<row>
|
||||||
|
<entry><para>Supports JSON</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>Supports BSON</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>Supports JSON Schema</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>Supports .NET 2.0</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>Supports .NET 3.5</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>Supports .NET 4.0</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>Supports Silverlight</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>Supports Windows Phone</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>Supports WinRT</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>Open Source</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>MIT License</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>LINQ to JSON</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>Thread Safe</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>XPath-like JSON query syntax</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>Indented JSON support</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>
|
||||||
|
<externalLink>
|
||||||
|
<linkText>Efficient dictionary serialization</linkText>
|
||||||
|
<linkUri>http://stackoverflow.com/questions/1207731/how-can-i-deserialize-json-to-a-simple-dictionarystring-string-in-asp-net</linkUri>
|
||||||
|
<linkTarget>_blank</linkTarget>
|
||||||
|
</externalLink>
|
||||||
|
</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>
|
||||||
|
<externalLink>
|
||||||
|
<linkText>Nonsensical dictionary serialization</linkText>
|
||||||
|
<linkUri>http://stackoverflow.com/questions/4559991/any-way-to-make-datacontractjsonserializer-serialize-dictionaries-properly</linkUri>
|
||||||
|
<linkTarget>_blank</linkTarget>
|
||||||
|
</externalLink>
|
||||||
|
</para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>Deserializes IList, IEnumerable, ICollection, IDictionary properties</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>Serializes circular references</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>Supports serializing objects by reference</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>Deserializes polymorphic properties and collections</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>Serializes and deserializes multidimensional arrays</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>Supports including type names with JSON</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>Globally customize serialization process</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>Supports excluding null values when serializing</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>Supports SerializationBinder</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>Conditional property serialization</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>Includes line number information in errors</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>Converts XML to JSON and JSON to XML</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>JSON Schema validation</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>JSON Schema generation from .NET types</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>Camel case JSON property names</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>Non-default constructors support</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>Serialization error handling</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>Supports populating an existing object</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>Efficiently serializes byte arrays as base64 text</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>Handles NaN, Infinity, -Infinity and undefined</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>Handles JavaScript constructors</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>Serializes .NET 4.0 dynamic objects</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>Serializes ISerializable objects</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>Supports serializing enums to their text name</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>JSON recursion limit support</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>Attribute property name customization</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>Attribute property order customization</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>Attribute property required customization</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>Supports ISO8601 dates</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>Supports JavaScript constructor dates</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>Supports Microsoft AJAX dates</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>Unquoted property names support</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>Raw JSON support</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>Supports reading and writing comments</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>Serializes anonymous types</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>Deserializes anonymous types</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>Opt-in mode serialization</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>Opt-out mode serialization</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>Field (Serializable) mode serialization</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>Efficiently stream reading and writing JSON</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>Single or double quote JSON content</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>Supports overriding a type's serialization</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>Supports OnDeserialized, OnSerializing, OnSerialized and OnDeserializing attributes</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>Supports serializing private properties</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>DataMember attribute support</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>MetdataType attribute support</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>DefaultValue attribute support</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>Serializes DataSets and DataTables</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>Serailizes Entity Framework</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>Serializes nHibernate</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><para>Case-insensitive property deserialization</para></entry>
|
||||||
|
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
|
||||||
|
</row>
|
||||||
|
</table>
|
||||||
|
</content>
|
||||||
|
</section>
|
||||||
|
<section>
|
||||||
|
<title>Benchmarks</title>
|
||||||
|
<content>
|
||||||
|
|
||||||
|
<mediaLink>
|
||||||
|
<image class="image" xlink:href="performance" mimeType="image/png" width="643" height="345" />
|
||||||
|
<summary>Json.NET Performance</summary>
|
||||||
|
</mediaLink>
|
||||||
|
|
||||||
|
</content>
|
||||||
|
</section>
|
||||||
|
</developerConceptualDocument>
|
||||||
|
</topic>
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<topic id="JsonNetVsWindowsDataJson" revisionNumber="1">
|
||||||
|
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||||
|
<introduction>
|
||||||
|
<para>Windows 8 introduces a new way to work with JSON via the <externalLink>
|
||||||
|
<linkText>Windows.Data.Json</linkText>
|
||||||
|
<linkUri>http://msdn.microsoft.com/en-us/library/windows/apps/xaml/br240639.aspx</linkUri>
|
||||||
|
<linkTarget>_blank</linkTarget>
|
||||||
|
</externalLink> namespace. Similar to LINQ to JSON in Json.NET
|
||||||
|
it defines classes that can be used to parse values, strings, objects, and arrays from
|
||||||
|
JSON text or serialize value types into JSON text.</para>
|
||||||
|
<para>Below is a comparison of Json.NET's LINQ to JSON to Window 8's Windows.Data.Json.</para>
|
||||||
|
</introduction>
|
||||||
|
<section>
|
||||||
|
<title>Exclusive Json.NET Features</title>
|
||||||
|
<content>
|
||||||
|
<list class="bullet">
|
||||||
|
<listItem>
|
||||||
|
<para>
|
||||||
|
Runs on .NET 2, .NET 3, .NET 4, Silverlight and Windows Phone 7
|
||||||
|
</para>
|
||||||
|
</listItem>
|
||||||
|
<listItem>
|
||||||
|
<para>
|
||||||
|
Supports dynamic programming
|
||||||
|
</para>
|
||||||
|
</listItem>
|
||||||
|
<listItem>
|
||||||
|
<para>
|
||||||
|
Write indented JSON
|
||||||
|
</para>
|
||||||
|
</listItem>
|
||||||
|
<listItem>
|
||||||
|
<para>
|
||||||
|
Customize reading and writing JSON with JsonConverters
|
||||||
|
</para>
|
||||||
|
</listItem>
|
||||||
|
<listItem>
|
||||||
|
<para>
|
||||||
|
Read and write ISO8601 dates
|
||||||
|
</para>
|
||||||
|
</listItem>
|
||||||
|
<listItem>
|
||||||
|
<para>
|
||||||
|
Better LINQ support
|
||||||
|
</para>
|
||||||
|
</listItem>
|
||||||
|
</list>
|
||||||
|
</content>
|
||||||
|
</section>
|
||||||
|
<section>
|
||||||
|
<title>Creating JSON</title>
|
||||||
|
<content>
|
||||||
|
<para>The big difference between the two libraries when creating JSON is Windows.Data.Json requires
|
||||||
|
string/integer/double values to be explicitly converted to JsonValue objects.</para>
|
||||||
|
<para>Note that there is a weird limitation to creating JSON with Windows.Data.Json: it doesn't
|
||||||
|
allow you to set properties to null or put null values in an array.</para>
|
||||||
|
|
||||||
|
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\JsonNetVsWindowsDataJsonTests.cs" region="CreatingJSON" title="Creating JSON with Json.NET and Windows.Data.Json" />
|
||||||
|
|
||||||
|
</content>
|
||||||
|
</section>
|
||||||
|
<section>
|
||||||
|
<title>Querying JSON</title>
|
||||||
|
<content>
|
||||||
|
<para>Windows.Data.Json requires a value to be cast to its exact type with the GetObject/GetArray methods
|
||||||
|
before it can be used, making Windows.Data.Json's code verbose compared to LINQ to JSON.</para>
|
||||||
|
|
||||||
|
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\JsonNetVsWindowsDataJsonTests.cs" region="QueryingJSON" title="Querying JSON with Json.NET and Windows.Data.Json" />
|
||||||
|
|
||||||
|
</content>
|
||||||
|
</section>
|
||||||
|
<section>
|
||||||
|
<title>Performance</title>
|
||||||
|
<content>
|
||||||
|
<para>Json.NET is slightly slower at writing JSON than Windows.Data.Json but considerably faster at parsing JSON.</para>
|
||||||
|
|
||||||
|
<mediaLink>
|
||||||
|
<image class="image" xlink:href="jsonnetwindowsdatajson" mimeType="image/png" width="592" height="356" />
|
||||||
|
<summary>Json.NET and Windows.Data.Json Performance</summary>
|
||||||
|
</mediaLink>
|
||||||
|
|
||||||
|
</content>
|
||||||
|
</section>
|
||||||
|
<section>
|
||||||
|
<title>Converting Between LINQ to JSON and Windows.Data.Json</title>
|
||||||
|
<content>
|
||||||
|
<para>Json.NET supports converting between the types of the two libraries.
|
||||||
|
This feature is useful if you are working with another API but you want to use Json.NET inside your own code.</para>
|
||||||
|
<para>Use <codeEntityReference>Overload:Newtonsoft.Json.Linq.JToken.FromObject</codeEntityReference> to convert a Windows.Data.Json
|
||||||
|
value to LINQ to JSON and use <codeEntityReference>Overload:Newtonsoft.Json.Linq.JToken.ToObject</codeEntityReference> to convert LINQ to JSON to Windows.Data.Json.</para>
|
||||||
|
|
||||||
|
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\JsonNetVsWindowsDataJsonTests.cs" region="Converting" title="Converting between Json.NET and Windows.Data.Json" />
|
||||||
|
|
||||||
|
</content>
|
||||||
|
</section>
|
||||||
|
<relatedTopics>
|
||||||
|
<codeEntityReference>N:Newtonsoft.Json.Linq</codeEntityReference>
|
||||||
|
</relatedTopics>
|
||||||
|
</developerConceptualDocument>
|
||||||
|
</topic>
|
||||||
+83
-83
@@ -1,84 +1,84 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<topic id="Performance" revisionNumber="1">
|
<topic id="Performance" revisionNumber="1">
|
||||||
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
|
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||||
<introduction>
|
<introduction>
|
||||||
<para>Out of the box Json.NET is faster than DataContractJsonSerializer and JavaScriptSerializer.
|
<para>Out of the box Json.NET is faster than DataContractJsonSerializer and JavaScriptSerializer.
|
||||||
Here are some tips to make it go even faster.</para>
|
Here are some tips to make it go even faster.</para>
|
||||||
</introduction>
|
</introduction>
|
||||||
<section>
|
<section>
|
||||||
<title>Optimize Memory Usage</title>
|
<title>Optimize Memory Usage</title>
|
||||||
<content>
|
<content>
|
||||||
<para>To keep an application consistantly fast it is important to minimize the
|
<para>To keep an application consistantly fast it is important to minimize the
|
||||||
amount of time the .NET framework spends performing <externalLink>
|
amount of time the .NET framework spends performing <externalLink>
|
||||||
<linkText>garbage collection</linkText>
|
<linkText>garbage collection</linkText>
|
||||||
<linkUri>http://msdn.microsoft.com/en-us/library/ms973837.aspx</linkUri>
|
<linkUri>http://msdn.microsoft.com/en-us/library/ms973837.aspx</linkUri>
|
||||||
<linkTarget>_blank</linkTarget>
|
<linkTarget>_blank</linkTarget>
|
||||||
</externalLink>.
|
</externalLink>.
|
||||||
Allocating too many objects, or allocating very large objects can slow down or even
|
Allocating too many objects, or allocating very large objects can slow down or even
|
||||||
halt an application while garbage collection is in progress.
|
halt an application while garbage collection is in progress.
|
||||||
</para>
|
</para>
|
||||||
<para>To minimize memory usage and the number of objects allocated Json.NET supports
|
<para>To minimize memory usage and the number of objects allocated Json.NET supports
|
||||||
serializing and deserializing directly to a stream. Reading or writing JSON a piece at a time instead of having
|
serializing and deserializing directly to a stream. Reading or writing JSON a piece at a time instead of having
|
||||||
the entire JSON string loaded into memory is especially important when working with JSON
|
the entire JSON string loaded into memory is especially important when working with JSON
|
||||||
documents greater than 85kb in size to avoid the JSON string ending up in the <externalLink>
|
documents greater than 85kb in size to avoid the JSON string ending up in the <externalLink>
|
||||||
<linkText>large object heap</linkText>
|
<linkText>large object heap</linkText>
|
||||||
<linkUri>http://msdn.microsoft.com/en-us/magazine/cc534993.aspx</linkUri>
|
<linkUri>http://msdn.microsoft.com/en-us/magazine/cc534993.aspx</linkUri>
|
||||||
<linkTarget>_blank</linkTarget>
|
<linkTarget>_blank</linkTarget>
|
||||||
</externalLink>.</para>
|
</externalLink>.</para>
|
||||||
|
|
||||||
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\PerformanceTests.cs" region="DeserializeString" title="Deserialize String" />
|
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\PerformanceTests.cs" region="DeserializeString" title="Deserialize String" />
|
||||||
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\PerformanceTests.cs" region="DeserializeStream" title="Deserialize Stream" />
|
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\PerformanceTests.cs" region="DeserializeStream" title="Deserialize Stream" />
|
||||||
|
|
||||||
</content>
|
</content>
|
||||||
</section>
|
</section>
|
||||||
<section>
|
<section>
|
||||||
<title>JsonConverters</title>
|
<title>JsonConverters</title>
|
||||||
<content>
|
<content>
|
||||||
<para>Passing a <codeEntityReference>T:Newtonsoft.Json.JsonConverter</codeEntityReference> to SerializeObject or DeserializeObject provides a simple way to completely
|
<para>Passing a <codeEntityReference>T:Newtonsoft.Json.JsonConverter</codeEntityReference> to SerializeObject or DeserializeObject provides a simple way to completely
|
||||||
change how an object is serialized. There is however a small overhead; the CanConvert method is called for every
|
change how an object is serialized. There is however a small overhead; the CanConvert method is called for every
|
||||||
type to check whether serialization should be handled by that JsonConverter.</para>
|
value to check whether serialization should be handled by that JsonConverter.</para>
|
||||||
<para>There are a couple of ways to continue to use JsonConverters without any overhead. The simplest way
|
<para>There are a couple of ways to continue to use JsonConverters without any overhead. The simplest way
|
||||||
is to specify the JsonConverter using the <codeEntityReference>T:Newtonsoft.Json.JsonConverterAttribute</codeEntityReference>. This attribute tells the serializer
|
is to specify the JsonConverter using the <codeEntityReference>T:Newtonsoft.Json.JsonConverterAttribute</codeEntityReference>. This attribute tells the serializer
|
||||||
to always use that converter when serializing and deserializing the type, without the check.</para>
|
to always use that converter when serializing and deserializing the type, without the check.</para>
|
||||||
|
|
||||||
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\PerformanceTests.cs" region="JsonConverterAttribute" title="Use JsonConverter with JsonConverterAttribute" />
|
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\PerformanceTests.cs" region="JsonConverterAttribute" title="Use JsonConverter with JsonConverterAttribute" />
|
||||||
|
|
||||||
<para>If the class you want to convert isn't your own and you're unable to use an attribute a JsonConverter can still be used by
|
<para>If the class you want to convert isn't your own and you're unable to use an attribute a JsonConverter can still be used by
|
||||||
creating your own <codeEntityReference>T:Newtonsoft.Json.Serialization.IContractResolver</codeEntityReference>.</para>
|
creating your own <codeEntityReference>T:Newtonsoft.Json.Serialization.IContractResolver</codeEntityReference>.</para>
|
||||||
|
|
||||||
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\PerformanceTests.cs" region="JsonConverterContractResolver" title="Use JsonConverter with IContractResolver" />
|
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\PerformanceTests.cs" region="JsonConverterContractResolver" title="Use JsonConverter with IContractResolver" />
|
||||||
|
|
||||||
<para>The IContractResolver in the example above will set all DateTimes to use the JavaScriptDateConverter.</para>
|
<para>The IContractResolver in the example above will set all DateTimes to use the JavaScriptDateConverter.</para>
|
||||||
</content>
|
</content>
|
||||||
</section>
|
</section>
|
||||||
<section>
|
<section>
|
||||||
<title>Manually Serialize</title>
|
<title>Manually Serialize</title>
|
||||||
<content>
|
<content>
|
||||||
<para>The absolute fastest way to read and write JSON is to use JsonTextReader and JsonTextWriter directly. Using a reader or writer
|
<para>The absolute fastest way to read and write JSON is to use JsonTextReader/JsonTextWriter directly to manually serialize types.
|
||||||
directly skips any of the overhead from a serializer such as reflection.</para>
|
Using a reader or writer directly skips any of the overhead from a serializer such as reflection.</para>
|
||||||
|
|
||||||
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\PerformanceTests.cs" region="ReaderWriter" title="Manually serialize using JsonTextWriter" />
|
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\PerformanceTests.cs" region="ReaderWriter" title="Manually serialize using JsonTextWriter" />
|
||||||
|
|
||||||
<para>If performance is important and you don't mind more code to get it then this is your best choice.</para>
|
<para>If performance is important and you don't mind more code to get it then this is your best choice.</para>
|
||||||
</content>
|
</content>
|
||||||
</section>
|
</section>
|
||||||
<section>
|
<section>
|
||||||
<title>Benchmarks</title>
|
<title>Benchmarks</title>
|
||||||
<content>
|
<content>
|
||||||
|
|
||||||
<mediaLink>
|
<mediaLink>
|
||||||
<image class="image" xlink:href="performance" mimeType="image/png" width="643" height="345" />
|
<image class="image" xlink:href="performance" mimeType="image/png" width="643" height="345" />
|
||||||
<summary>Json.NET Performance</summary>
|
<summary>Json.NET Performance</summary>
|
||||||
</mediaLink>
|
</mediaLink>
|
||||||
|
|
||||||
</content>
|
</content>
|
||||||
</section>
|
</section>
|
||||||
<relatedTopics>
|
<relatedTopics>
|
||||||
<codeEntityReference>T:Newtonsoft.Json.JsonSerializer</codeEntityReference>
|
<codeEntityReference>T:Newtonsoft.Json.JsonSerializer</codeEntityReference>
|
||||||
<codeEntityReference>T:Newtonsoft.Json.JsonConverter</codeEntityReference>
|
<codeEntityReference>T:Newtonsoft.Json.JsonConverter</codeEntityReference>
|
||||||
<codeEntityReference>T:Newtonsoft.Json.JsonConverterAttribute</codeEntityReference>
|
<codeEntityReference>T:Newtonsoft.Json.JsonConverterAttribute</codeEntityReference>
|
||||||
<codeEntityReference>T:Newtonsoft.Json.JsonTextWriter</codeEntityReference>
|
<codeEntityReference>T:Newtonsoft.Json.JsonTextWriter</codeEntityReference>
|
||||||
<codeEntityReference>T:Newtonsoft.Json.JsonTextReader</codeEntityReference>
|
<codeEntityReference>T:Newtonsoft.Json.JsonTextReader</codeEntityReference>
|
||||||
</relatedTopics>
|
</relatedTopics>
|
||||||
</developerConceptualDocument>
|
</developerConceptualDocument>
|
||||||
</topic>
|
</topic>
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 655 B |
+5
-2
@@ -9,11 +9,12 @@
|
|||||||
<Topic id="SerializationErrorHandling" visible="True" title="Serialization Error Handling" />
|
<Topic id="SerializationErrorHandling" visible="True" title="Serialization Error Handling" />
|
||||||
<Topic id="PreserveObjectReferences" visible="True" title="Preserving Object References" />
|
<Topic id="PreserveObjectReferences" visible="True" title="Preserving Object References" />
|
||||||
<Topic id="CustomCreationConverter" visible="True" />
|
<Topic id="CustomCreationConverter" visible="True" />
|
||||||
<Topic id="ContractResolver" visible="True" />
|
|
||||||
<Topic id="SerializingCollections" visible="True" title="Serializing Collections" />
|
<Topic id="SerializingCollections" visible="True" title="Serializing Collections" />
|
||||||
<Topic id="DatesInJSON" visible="True" title="Serializing Dates in JSON" />
|
<Topic id="DatesInJSON" visible="True" title="Serializing Dates in JSON" />
|
||||||
<Topic id="ReducingSerializedJSONSize" visible="True" title="Reducing Serialized JSON Size" />
|
<Topic id="ReducingSerializedJSONSize" visible="True" title="Reducing Serialized JSON Size" />
|
||||||
<Topic id="SerializingJSONFragments" visible="True" title="Serializing Partial JSON Fragments" />
|
<Topic id="SerializingJSONFragments" visible="True" title="Serializing Partial JSON Fragments" />
|
||||||
|
<Topic id="ConditionalProperties" visible="True" title="Conditional Properties" />
|
||||||
|
<Topic id="ContractResolver" visible="True" title="Serialization using ContractResolver" />
|
||||||
</Topic>
|
</Topic>
|
||||||
<Topic id="LINQtoJSON" visible="True" title="LINQ to JSON">
|
<Topic id="LINQtoJSON" visible="True" title="LINQ to JSON">
|
||||||
<Topic id="ParsingLINQtoJSON" visible="True" title="Parsing JSON" />
|
<Topic id="ParsingLINQtoJSON" visible="True" title="Parsing JSON" />
|
||||||
@@ -21,8 +22,10 @@
|
|||||||
<Topic id="QueryingLINQtoJSON" visible="True" title="Querying JSON with LINQ" />
|
<Topic id="QueryingLINQtoJSON" visible="True" title="Querying JSON with LINQ" />
|
||||||
<Topic id="SelectToken" visible="True" title="Querying JSON with SelectToken" />
|
<Topic id="SelectToken" visible="True" title="Querying JSON with SelectToken" />
|
||||||
</Topic>
|
</Topic>
|
||||||
<Topic id="Performance" visible="True" isSelected="true" title="Performance" />
|
<Topic id="Performance" visible="True" title="Performance" />
|
||||||
<Topic id="JsonSchema" visible="True" title="Validating JSON" />
|
<Topic id="JsonSchema" visible="True" title="Validating JSON" />
|
||||||
<Topic id="ReadingWritingJSON" visible="True" title="Basic Reading and Writing JSON" />
|
<Topic id="ReadingWritingJSON" visible="True" title="Basic Reading and Writing JSON" />
|
||||||
<Topic id="ConvertingJSONandXML" visible="True" title="Converting between JSON and XML" />
|
<Topic id="ConvertingJSONandXML" visible="True" title="Converting between JSON and XML" />
|
||||||
|
<Topic id="JsonNetVsWindowsDataJson" visible="True" title="Json.NET vs Windows.Data.Json" />
|
||||||
|
<Topic id="JsonNetVsDotNetSerializers" visible="True" isSelected="true" title="Json.NET vs .NET Serializers" />
|
||||||
</Topics>
|
</Topics>
|
||||||
+18
-3
@@ -8,7 +8,7 @@
|
|||||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
<SchemaVersion>2.0</SchemaVersion>
|
<SchemaVersion>2.0</SchemaVersion>
|
||||||
<ProjectGuid>{fd19f68e-72c8-4576-9775-b4480b0db686}</ProjectGuid>
|
<ProjectGuid>{fd19f68e-72c8-4576-9775-b4480b0db686}</ProjectGuid>
|
||||||
<SHFBSchemaVersion>1.9.3.0</SHFBSchemaVersion>
|
<SHFBSchemaVersion>1.9.5.0</SHFBSchemaVersion>
|
||||||
<!-- AssemblyName, Name, and RootNamespace are not used by SHFB but Visual
|
<!-- AssemblyName, Name, and RootNamespace are not used by SHFB but Visual
|
||||||
Studio adds them anyway -->
|
Studio adds them anyway -->
|
||||||
<AssemblyName>Documentation</AssemblyName>
|
<AssemblyName>Documentation</AssemblyName>
|
||||||
@@ -32,7 +32,7 @@
|
|||||||
<BuildLogFile>
|
<BuildLogFile>
|
||||||
</BuildLogFile>
|
</BuildLogFile>
|
||||||
<HelpFileFormat>Website</HelpFileFormat>
|
<HelpFileFormat>Website</HelpFileFormat>
|
||||||
<FrameworkVersion>.NET 4.0.30319</FrameworkVersion>
|
<FrameworkVersion>.NET Framework 4.0</FrameworkVersion>
|
||||||
<HelpTitle>Json.NET - Documentation</HelpTitle>
|
<HelpTitle>Json.NET - Documentation</HelpTitle>
|
||||||
<PresentationStyle>vs2005</PresentationStyle>
|
<PresentationStyle>vs2005</PresentationStyle>
|
||||||
<NamingMethod>MemberName</NamingMethod>
|
<NamingMethod>MemberName</NamingMethod>
|
||||||
@@ -70,7 +70,7 @@
|
|||||||
</outputPaths>
|
</outputPaths>
|
||||||
<!-- Logo image file (optional). Filename is required. The height, width, altText, placement, and
|
<!-- Logo image file (optional). Filename is required. The height, width, altText, placement, and
|
||||||
alignment attributes are optional. -->
|
alignment attributes are optional. -->
|
||||||
<logoFile filename="D:\Development\Source\Json\Newtonsoft.Json\Doc\logo.jpg" height="0" width="0" altText="Json.NET" placement="left" alignment="left" />
|
<logoFile filename="{@ProjectFolder}logo.jpg" height="0" width="0" altText="Json.NET" placement="left" alignment="left" />
|
||||||
</component>
|
</component>
|
||||||
</ComponentConfig>
|
</ComponentConfig>
|
||||||
<ComponentConfig id="Code Block Component" enabled="True">
|
<ComponentConfig id="Code Block Component" enabled="True">
|
||||||
@@ -137,6 +137,9 @@
|
|||||||
<Content Include="donate.gif" />
|
<Content Include="donate.gif" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<None Include="JsonNetVsDotNetSerializers.aml" />
|
||||||
|
<None Include="JsonNetVsWindowsDataJson.aml" />
|
||||||
|
<None Include="ConditionalProperties.aml" />
|
||||||
<None Include="CustomCreationConverter.aml" />
|
<None Include="CustomCreationConverter.aml" />
|
||||||
<None Include="ContractResolver.aml" />
|
<None Include="ContractResolver.aml" />
|
||||||
<None Include="ConvertingJSONandXML.aml" />
|
<None Include="ConvertingJSONandXML.aml" />
|
||||||
@@ -166,6 +169,18 @@
|
|||||||
<ContentLayout Include="doc.content" />
|
<ContentLayout Include="doc.content" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Content Include="tick.png">
|
||||||
|
<ImageId>tick</ImageId>
|
||||||
|
<AlternateText>tick</AlternateText>
|
||||||
|
</Content>
|
||||||
|
<Content Include="cross.png">
|
||||||
|
<ImageId>cross</ImageId>
|
||||||
|
<AlternateText>cross</AlternateText>
|
||||||
|
</Content>
|
||||||
|
<Image Include="jsonnetwindowsdatajson.png">
|
||||||
|
<ImageId>jsonnetwindowsdatajson</ImageId>
|
||||||
|
<AlternateText>jsonnetwindowsdatajson</AlternateText>
|
||||||
|
</Image>
|
||||||
<Image Include="performance.png">
|
<Image Include="performance.png">
|
||||||
<ImageId>performance</ImageId>
|
<ImageId>performance</ImageId>
|
||||||
<AlternateText>performance</AlternateText>
|
<AlternateText>performance</AlternateText>
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 6.4 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 537 B |
@@ -0,0 +1,177 @@
|
|||||||
|
#region License
|
||||||
|
// Copyright (c) 2007 James Newton-King
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person
|
||||||
|
// obtaining a copy of this software and associated documentation
|
||||||
|
// files (the "Software"), to deal in the Software without
|
||||||
|
// restriction, including without limitation the rights to use,
|
||||||
|
// copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the
|
||||||
|
// Software is furnished to do so, subject to the following
|
||||||
|
// conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be
|
||||||
|
// included in all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||||
|
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||||
|
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||||
|
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||||
|
// OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#if !(NET35 || NET20 || PORTABLE)
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Dynamic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.Serialization;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Newtonsoft.Json.Converters;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
#if !NETFX_CORE
|
||||||
|
using NUnit.Framework;
|
||||||
|
#else
|
||||||
|
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
||||||
|
using TestFixture = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestClassAttribute;
|
||||||
|
using Test = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestMethodAttribute;
|
||||||
|
#endif
|
||||||
|
using Newtonsoft.Json.Serialization;
|
||||||
|
using Newtonsoft.Json.Tests.TestObjects;
|
||||||
|
using Newtonsoft.Json.Utilities;
|
||||||
|
using System.Globalization;
|
||||||
|
|
||||||
|
namespace Newtonsoft.Json.Tests.Documentation
|
||||||
|
{
|
||||||
|
public class Employee
|
||||||
|
{
|
||||||
|
public string Name { get; set; }
|
||||||
|
public Employee Manager { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
#region ShouldSerializeContractResolver
|
||||||
|
public class ShouldSerializeContractResolver : DefaultContractResolver
|
||||||
|
{
|
||||||
|
public new static readonly ShouldSerializeContractResolver Instance = new ShouldSerializeContractResolver();
|
||||||
|
|
||||||
|
protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
|
||||||
|
{
|
||||||
|
JsonProperty property = base.CreateProperty(member, memberSerialization);
|
||||||
|
|
||||||
|
if (property.DeclaringType == typeof(Employee) && property.PropertyName == "Manager")
|
||||||
|
{
|
||||||
|
property.ShouldSerialize =
|
||||||
|
instance =>
|
||||||
|
{
|
||||||
|
Employee e = (Employee) instance;
|
||||||
|
return e.Manager != e;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return property;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
[TestFixture]
|
||||||
|
public class ConditionalPropertiesTests : TestFixtureBase
|
||||||
|
{
|
||||||
|
#region EmployeeShouldSerializeExample
|
||||||
|
public class Employee
|
||||||
|
{
|
||||||
|
public string Name { get; set; }
|
||||||
|
public Employee Manager { get; set; }
|
||||||
|
|
||||||
|
public bool ShouldSerializeManager()
|
||||||
|
{
|
||||||
|
// don't serialize the Manager property if an employee is their own manager
|
||||||
|
return (Manager != this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void ShouldSerializeClassTest()
|
||||||
|
{
|
||||||
|
#region ShouldSerializeClassTest
|
||||||
|
Employee joe = new Employee();
|
||||||
|
joe.Name = "Joe Employee";
|
||||||
|
Employee mike = new Employee();
|
||||||
|
mike.Name = "Mike Manager";
|
||||||
|
|
||||||
|
joe.Manager = mike;
|
||||||
|
|
||||||
|
// mike is his own manager
|
||||||
|
// ShouldSerialize will skip this property
|
||||||
|
mike.Manager = mike;
|
||||||
|
|
||||||
|
string json = JsonConvert.SerializeObject(new[] { joe, mike }, Formatting.Indented);
|
||||||
|
// [
|
||||||
|
// {
|
||||||
|
// "Name": "Joe Employee",
|
||||||
|
// "Manager": {
|
||||||
|
// "Name": "Mike Manager"
|
||||||
|
// }
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// "Name": "Mike Manager"
|
||||||
|
// }
|
||||||
|
// ]
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
Assert.AreEqual(@"[
|
||||||
|
{
|
||||||
|
""Name"": ""Joe Employee"",
|
||||||
|
""Manager"": {
|
||||||
|
""Name"": ""Mike Manager""
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
""Name"": ""Mike Manager""
|
||||||
|
}
|
||||||
|
]", json);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void ShouldSerializeContractResolverTest()
|
||||||
|
{
|
||||||
|
Newtonsoft.Json.Tests.Documentation.Employee joe = new Newtonsoft.Json.Tests.Documentation.Employee();
|
||||||
|
joe.Name = "Joe Employee";
|
||||||
|
Newtonsoft.Json.Tests.Documentation.Employee mike = new Newtonsoft.Json.Tests.Documentation.Employee();
|
||||||
|
mike.Name = "Mike Manager";
|
||||||
|
|
||||||
|
joe.Manager = mike;
|
||||||
|
mike.Manager = mike;
|
||||||
|
|
||||||
|
string json = JsonConvert.SerializeObject(
|
||||||
|
new[] {joe, mike},
|
||||||
|
Formatting.Indented,
|
||||||
|
new JsonSerializerSettings
|
||||||
|
{
|
||||||
|
ContractResolver = ShouldSerializeContractResolver.Instance
|
||||||
|
});
|
||||||
|
|
||||||
|
Assert.AreEqual(@"[
|
||||||
|
{
|
||||||
|
""Name"": ""Joe Employee"",
|
||||||
|
""Manager"": {
|
||||||
|
""Name"": ""Mike Manager""
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
""Name"": ""Mike Manager""
|
||||||
|
}
|
||||||
|
]", json);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,108 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
|
namespace Newtonsoft.Json.Tests.Documentation
|
||||||
|
{
|
||||||
|
public class JsonNetVsWindowsDataJsonTests
|
||||||
|
{
|
||||||
|
public void CreatingJson()
|
||||||
|
{
|
||||||
|
#if NETFX_CORE
|
||||||
|
#region CreatingJSON
|
||||||
|
// Windows.Data.Json
|
||||||
|
// -----------------
|
||||||
|
JsonObject jsonObject = new JsonObject
|
||||||
|
{
|
||||||
|
{"CPU", JsonValue.CreateStringValue("Intel")},
|
||||||
|
{
|
||||||
|
"Drives", new JsonArray
|
||||||
|
{
|
||||||
|
JsonValue.CreateStringValue("DVD read/writer"),
|
||||||
|
JsonValue.CreateStringValue("500 gigabyte hard drive")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
string json1 = jsonObject.Stringify();
|
||||||
|
|
||||||
|
// LINQ to JSON
|
||||||
|
// ------------
|
||||||
|
JObject jObject = new JObject
|
||||||
|
{
|
||||||
|
{"CPU", "Intel"},
|
||||||
|
{
|
||||||
|
"Drives", new JArray
|
||||||
|
{
|
||||||
|
"DVD read/writer",
|
||||||
|
"500 gigabyte hard drive"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
string json2 = jObject.ToString();
|
||||||
|
#endregion
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
public void QueryingJson()
|
||||||
|
{
|
||||||
|
#if NETFX_CORE
|
||||||
|
#region QueryingJSON
|
||||||
|
string json = @"{
|
||||||
|
'channel': {
|
||||||
|
'title': 'James Newton-King',
|
||||||
|
'link': 'http://james.newtonking.com',
|
||||||
|
'description': 'James Newton-King's blog.',
|
||||||
|
'item': [
|
||||||
|
{
|
||||||
|
'title': 'Json.NET 1.3 + New license + Now on CodePlex',
|
||||||
|
'description': 'Annoucing the release of Json.NET 1.3, the MIT license and the source being available on CodePlex',
|
||||||
|
'link': 'http://james.newtonking.com/projects/json-net.aspx',
|
||||||
|
'category': [
|
||||||
|
'Json.NET',
|
||||||
|
'CodePlex'
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}";
|
||||||
|
|
||||||
|
// Windows.Data.Json
|
||||||
|
// -----------------
|
||||||
|
JsonObject jsonObject = JsonObject.Parse(json);
|
||||||
|
string itemTitle1 = jsonObject["channel"].GetObject()["item"].GetArray()[0].GetObject()["title"].GetString();
|
||||||
|
|
||||||
|
// LINQ to JSON
|
||||||
|
// ------------
|
||||||
|
JObject jObject = JObject.Parse(json);
|
||||||
|
string itemTitle2 = (string)jObject["channel"]["item"][0]["title"];
|
||||||
|
#endregion
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Converting()
|
||||||
|
{
|
||||||
|
#if NETFX_CORE
|
||||||
|
#region Converting
|
||||||
|
JsonObject jsonObject = new JsonObject
|
||||||
|
{
|
||||||
|
{"CPU", JsonValue.CreateStringValue("Intel")},
|
||||||
|
{"Drives", new JsonArray {
|
||||||
|
JsonValue.CreateStringValue("DVD read/writer"),
|
||||||
|
JsonValue.CreateStringValue("500 gigabyte hard drive")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// convert Windows.Data.Json to LINQ to JSON
|
||||||
|
JObject o = JObject.FromObject(jsonObject);
|
||||||
|
|
||||||
|
// convert LINQ to JSON to Windows.Data.Json
|
||||||
|
JArray a = (JArray)o["Drives"];
|
||||||
|
JsonArray jsonArray = a.ToObject<JsonArray>();
|
||||||
|
#endregion
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -80,10 +80,13 @@ namespace Newtonsoft.Json.Tests.Documentation
|
|||||||
#region JsonConverterContractResolver
|
#region JsonConverterContractResolver
|
||||||
public class ConverterContractResolver : DefaultContractResolver
|
public class ConverterContractResolver : DefaultContractResolver
|
||||||
{
|
{
|
||||||
|
public new static readonly ConverterContractResolver Instance = new ConverterContractResolver();
|
||||||
|
|
||||||
protected override JsonContract CreateContract(Type objectType)
|
protected override JsonContract CreateContract(Type objectType)
|
||||||
{
|
{
|
||||||
JsonContract contract = base.CreateContract(objectType);
|
JsonContract contract = base.CreateContract(objectType);
|
||||||
|
|
||||||
|
// this will only be called once and then cached
|
||||||
if (objectType == typeof(DateTime) || objectType == typeof(DateTimeOffset))
|
if (objectType == typeof(DateTime) || objectType == typeof(DateTimeOffset))
|
||||||
contract.Converter = new JavaScriptDateTimeConverter();
|
contract.Converter = new JavaScriptDateTimeConverter();
|
||||||
|
|
||||||
@@ -117,7 +120,7 @@ namespace Newtonsoft.Json.Tests.Documentation
|
|||||||
{
|
{
|
||||||
string json = JsonConvert.SerializeObject(new DateTime(2000, 10, 10, 10, 10, 10, DateTimeKind.Utc), new JsonSerializerSettings
|
string json = JsonConvert.SerializeObject(new DateTime(2000, 10, 10, 10, 10, 10, DateTimeKind.Utc), new JsonSerializerSettings
|
||||||
{
|
{
|
||||||
ContractResolver = new ConverterContractResolver()
|
ContractResolver = ConverterContractResolver.Instance
|
||||||
});
|
});
|
||||||
|
|
||||||
Console.WriteLine(json);
|
Console.WriteLine(json);
|
||||||
|
|||||||
@@ -713,6 +713,7 @@ _____'propertyName': NaN
|
|||||||
jsonWriter.WriteValue(data);
|
jsonWriter.WriteValue(data);
|
||||||
jsonWriter.WriteValue((object)data);
|
jsonWriter.WriteValue((object)data);
|
||||||
jsonWriter.WriteValue((byte[])null);
|
jsonWriter.WriteValue((byte[])null);
|
||||||
|
jsonWriter.WriteValue((Uri)null);
|
||||||
jsonWriter.WriteEndArray();
|
jsonWriter.WriteEndArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -720,6 +721,7 @@ _____'propertyName': NaN
|
|||||||
""SGVsbG8gd29ybGQu"",
|
""SGVsbG8gd29ybGQu"",
|
||||||
""SGVsbG8gd29ybGQu"",
|
""SGVsbG8gd29ybGQu"",
|
||||||
""SGVsbG8gd29ybGQu"",
|
""SGVsbG8gd29ybGQu"",
|
||||||
|
null,
|
||||||
null
|
null
|
||||||
]";
|
]";
|
||||||
string result = sb.ToString();
|
string result = sb.ToString();
|
||||||
|
|||||||
@@ -117,6 +117,7 @@
|
|||||||
<Compile Include="Converters\StringEnumConverterTests.cs" />
|
<Compile Include="Converters\StringEnumConverterTests.cs" />
|
||||||
<Compile Include="Converters\VersionConverterTests.cs" />
|
<Compile Include="Converters\VersionConverterTests.cs" />
|
||||||
<Compile Include="Documentation\ConvertingJsonAndXmlTests.cs" />
|
<Compile Include="Documentation\ConvertingJsonAndXmlTests.cs" />
|
||||||
|
<Compile Include="Documentation\ConditionalPropertiesTests.cs" />
|
||||||
<Compile Include="Documentation\PerformanceTests.cs" />
|
<Compile Include="Documentation\PerformanceTests.cs" />
|
||||||
<Compile Include="Documentation\JsonSchemaTests.cs" />
|
<Compile Include="Documentation\JsonSchemaTests.cs" />
|
||||||
<Compile Include="Documentation\ReadingAndWritingJsonTests.cs" />
|
<Compile Include="Documentation\ReadingAndWritingJsonTests.cs" />
|
||||||
|
|||||||
@@ -64,8 +64,8 @@ namespace Newtonsoft.Json.Tests
|
|||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class PerformanceTests : TestFixtureBase
|
public class PerformanceTests : TestFixtureBase
|
||||||
{
|
{
|
||||||
private const int Iterations = 100;
|
//private const int Iterations = 100;
|
||||||
//private const int Iterations = 5000;
|
private const int Iterations = 5000;
|
||||||
|
|
||||||
#region Data
|
#region Data
|
||||||
|
|
||||||
@@ -122,8 +122,6 @@ namespace Newtonsoft.Json.Tests
|
|||||||
TestClass test = CreateSerializationObject();
|
TestClass test = CreateSerializationObject();
|
||||||
|
|
||||||
SerializeTests(test);
|
SerializeTests(test);
|
||||||
|
|
||||||
Deserialize();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SerializeTests(object value)
|
private void SerializeTests(object value)
|
||||||
|
|||||||
@@ -76,5 +76,5 @@ using System.Security;
|
|||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
[assembly: AssemblyVersion("4.5.0.0")]
|
[assembly: AssemblyVersion("4.5.0.0")]
|
||||||
#if !PocketPC
|
#if !PocketPC
|
||||||
[assembly: AssemblyFileVersion("4.5.10.15427")]
|
[assembly: AssemblyFileVersion("4.5.10.15501")]
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -148,7 +148,7 @@ namespace Newtonsoft.Json
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public override void WriteStartObject()
|
public override void WriteStartObject()
|
||||||
{
|
{
|
||||||
base.WriteStartObject();
|
InternalWriteStart(JsonToken.StartObject, JsonContainerType.Object);
|
||||||
|
|
||||||
_writer.Write("{");
|
_writer.Write("{");
|
||||||
}
|
}
|
||||||
@@ -158,7 +158,7 @@ namespace Newtonsoft.Json
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public override void WriteStartArray()
|
public override void WriteStartArray()
|
||||||
{
|
{
|
||||||
base.WriteStartArray();
|
InternalWriteStart(JsonToken.StartArray, JsonContainerType.Array);
|
||||||
|
|
||||||
_writer.Write("[");
|
_writer.Write("[");
|
||||||
}
|
}
|
||||||
@@ -169,7 +169,7 @@ namespace Newtonsoft.Json
|
|||||||
/// <param name="name">The name of the constructor.</param>
|
/// <param name="name">The name of the constructor.</param>
|
||||||
public override void WriteStartConstructor(string name)
|
public override void WriteStartConstructor(string name)
|
||||||
{
|
{
|
||||||
base.WriteStartConstructor(name);
|
InternalWriteStart(JsonToken.StartConstructor, JsonContainerType.Constructor);
|
||||||
|
|
||||||
_writer.Write("new ");
|
_writer.Write("new ");
|
||||||
_writer.Write(name);
|
_writer.Write(name);
|
||||||
@@ -204,7 +204,7 @@ namespace Newtonsoft.Json
|
|||||||
/// <param name="name">The name of the property.</param>
|
/// <param name="name">The name of the property.</param>
|
||||||
public override void WritePropertyName(string name)
|
public override void WritePropertyName(string name)
|
||||||
{
|
{
|
||||||
base.WritePropertyName(name);
|
InternalWritePropertyName(name);
|
||||||
|
|
||||||
JavaScriptUtils.WriteEscapedJavaScriptString(_writer, name, _quoteChar, _quoteName);
|
JavaScriptUtils.WriteEscapedJavaScriptString(_writer, name, _quoteChar, _quoteName);
|
||||||
|
|
||||||
@@ -259,7 +259,7 @@ namespace Newtonsoft.Json
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public override void WriteNull()
|
public override void WriteNull()
|
||||||
{
|
{
|
||||||
base.WriteNull();
|
InternalWriteNull();
|
||||||
WriteValueInternal(JsonConvert.Null, JsonToken.Null);
|
WriteValueInternal(JsonConvert.Null, JsonToken.Null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -268,7 +268,7 @@ namespace Newtonsoft.Json
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public override void WriteUndefined()
|
public override void WriteUndefined()
|
||||||
{
|
{
|
||||||
base.WriteUndefined();
|
InternalWriteUndefined();
|
||||||
WriteValueInternal(JsonConvert.Undefined, JsonToken.Undefined);
|
WriteValueInternal(JsonConvert.Undefined, JsonToken.Undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -278,7 +278,7 @@ namespace Newtonsoft.Json
|
|||||||
/// <param name="json">The raw JSON to write.</param>
|
/// <param name="json">The raw JSON to write.</param>
|
||||||
public override void WriteRaw(string json)
|
public override void WriteRaw(string json)
|
||||||
{
|
{
|
||||||
base.WriteRaw(json);
|
InternalWriteRaw();
|
||||||
|
|
||||||
_writer.Write(json);
|
_writer.Write(json);
|
||||||
}
|
}
|
||||||
@@ -289,7 +289,8 @@ namespace Newtonsoft.Json
|
|||||||
/// <param name="value">The <see cref="String"/> value to write.</param>
|
/// <param name="value">The <see cref="String"/> value to write.</param>
|
||||||
public override void WriteValue(string value)
|
public override void WriteValue(string value)
|
||||||
{
|
{
|
||||||
base.WriteValue(value);
|
InternalWriteValue(JsonToken.String);
|
||||||
|
|
||||||
if (value == null)
|
if (value == null)
|
||||||
WriteValueInternal(JsonConvert.Null, JsonToken.Null);
|
WriteValueInternal(JsonConvert.Null, JsonToken.Null);
|
||||||
else
|
else
|
||||||
@@ -302,7 +303,7 @@ namespace Newtonsoft.Json
|
|||||||
/// <param name="value">The <see cref="Int32"/> value to write.</param>
|
/// <param name="value">The <see cref="Int32"/> value to write.</param>
|
||||||
public override void WriteValue(int value)
|
public override void WriteValue(int value)
|
||||||
{
|
{
|
||||||
base.WriteValue(value);
|
InternalWriteValue(JsonToken.Integer);
|
||||||
WriteValueInternal(JsonConvert.ToString(value), JsonToken.Integer);
|
WriteValueInternal(JsonConvert.ToString(value), JsonToken.Integer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -313,7 +314,7 @@ namespace Newtonsoft.Json
|
|||||||
[CLSCompliant(false)]
|
[CLSCompliant(false)]
|
||||||
public override void WriteValue(uint value)
|
public override void WriteValue(uint value)
|
||||||
{
|
{
|
||||||
base.WriteValue(value);
|
InternalWriteValue(JsonToken.Integer);
|
||||||
WriteValueInternal(JsonConvert.ToString(value), JsonToken.Integer);
|
WriteValueInternal(JsonConvert.ToString(value), JsonToken.Integer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -323,7 +324,7 @@ namespace Newtonsoft.Json
|
|||||||
/// <param name="value">The <see cref="Int64"/> value to write.</param>
|
/// <param name="value">The <see cref="Int64"/> value to write.</param>
|
||||||
public override void WriteValue(long value)
|
public override void WriteValue(long value)
|
||||||
{
|
{
|
||||||
base.WriteValue(value);
|
InternalWriteValue(JsonToken.Integer);
|
||||||
WriteValueInternal(JsonConvert.ToString(value), JsonToken.Integer);
|
WriteValueInternal(JsonConvert.ToString(value), JsonToken.Integer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -334,7 +335,7 @@ namespace Newtonsoft.Json
|
|||||||
[CLSCompliant(false)]
|
[CLSCompliant(false)]
|
||||||
public override void WriteValue(ulong value)
|
public override void WriteValue(ulong value)
|
||||||
{
|
{
|
||||||
base.WriteValue(value);
|
InternalWriteValue(JsonToken.Integer);
|
||||||
WriteValueInternal(JsonConvert.ToString(value), JsonToken.Integer);
|
WriteValueInternal(JsonConvert.ToString(value), JsonToken.Integer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -344,7 +345,7 @@ namespace Newtonsoft.Json
|
|||||||
/// <param name="value">The <see cref="Single"/> value to write.</param>
|
/// <param name="value">The <see cref="Single"/> value to write.</param>
|
||||||
public override void WriteValue(float value)
|
public override void WriteValue(float value)
|
||||||
{
|
{
|
||||||
base.WriteValue(value);
|
InternalWriteValue(JsonToken.Float);
|
||||||
WriteValueInternal(JsonConvert.ToString(value), JsonToken.Float);
|
WriteValueInternal(JsonConvert.ToString(value), JsonToken.Float);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -354,7 +355,7 @@ namespace Newtonsoft.Json
|
|||||||
/// <param name="value">The <see cref="Double"/> value to write.</param>
|
/// <param name="value">The <see cref="Double"/> value to write.</param>
|
||||||
public override void WriteValue(double value)
|
public override void WriteValue(double value)
|
||||||
{
|
{
|
||||||
base.WriteValue(value);
|
InternalWriteValue(JsonToken.Float);
|
||||||
WriteValueInternal(JsonConvert.ToString(value), JsonToken.Float);
|
WriteValueInternal(JsonConvert.ToString(value), JsonToken.Float);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -364,7 +365,7 @@ namespace Newtonsoft.Json
|
|||||||
/// <param name="value">The <see cref="Boolean"/> value to write.</param>
|
/// <param name="value">The <see cref="Boolean"/> value to write.</param>
|
||||||
public override void WriteValue(bool value)
|
public override void WriteValue(bool value)
|
||||||
{
|
{
|
||||||
base.WriteValue(value);
|
InternalWriteValue(JsonToken.Boolean);
|
||||||
WriteValueInternal(JsonConvert.ToString(value), JsonToken.Boolean);
|
WriteValueInternal(JsonConvert.ToString(value), JsonToken.Boolean);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -374,7 +375,7 @@ namespace Newtonsoft.Json
|
|||||||
/// <param name="value">The <see cref="Int16"/> value to write.</param>
|
/// <param name="value">The <see cref="Int16"/> value to write.</param>
|
||||||
public override void WriteValue(short value)
|
public override void WriteValue(short value)
|
||||||
{
|
{
|
||||||
base.WriteValue(value);
|
InternalWriteValue(JsonToken.Integer);
|
||||||
WriteValueInternal(JsonConvert.ToString(value), JsonToken.Integer);
|
WriteValueInternal(JsonConvert.ToString(value), JsonToken.Integer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -385,7 +386,7 @@ namespace Newtonsoft.Json
|
|||||||
[CLSCompliant(false)]
|
[CLSCompliant(false)]
|
||||||
public override void WriteValue(ushort value)
|
public override void WriteValue(ushort value)
|
||||||
{
|
{
|
||||||
base.WriteValue(value);
|
InternalWriteValue(JsonToken.Integer);
|
||||||
WriteValueInternal(JsonConvert.ToString(value), JsonToken.Integer);
|
WriteValueInternal(JsonConvert.ToString(value), JsonToken.Integer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -395,8 +396,8 @@ namespace Newtonsoft.Json
|
|||||||
/// <param name="value">The <see cref="Char"/> value to write.</param>
|
/// <param name="value">The <see cref="Char"/> value to write.</param>
|
||||||
public override void WriteValue(char value)
|
public override void WriteValue(char value)
|
||||||
{
|
{
|
||||||
base.WriteValue(value);
|
InternalWriteValue(JsonToken.String);
|
||||||
WriteValueInternal(JsonConvert.ToString(value), JsonToken.Integer);
|
WriteValueInternal(JsonConvert.ToString(value), JsonToken.String);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -405,7 +406,7 @@ namespace Newtonsoft.Json
|
|||||||
/// <param name="value">The <see cref="Byte"/> value to write.</param>
|
/// <param name="value">The <see cref="Byte"/> value to write.</param>
|
||||||
public override void WriteValue(byte value)
|
public override void WriteValue(byte value)
|
||||||
{
|
{
|
||||||
base.WriteValue(value);
|
InternalWriteValue(JsonToken.Integer);
|
||||||
WriteValueInternal(JsonConvert.ToString(value), JsonToken.Integer);
|
WriteValueInternal(JsonConvert.ToString(value), JsonToken.Integer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -416,7 +417,7 @@ namespace Newtonsoft.Json
|
|||||||
[CLSCompliant(false)]
|
[CLSCompliant(false)]
|
||||||
public override void WriteValue(sbyte value)
|
public override void WriteValue(sbyte value)
|
||||||
{
|
{
|
||||||
base.WriteValue(value);
|
InternalWriteValue(JsonToken.Integer);
|
||||||
WriteValueInternal(JsonConvert.ToString(value), JsonToken.Integer);
|
WriteValueInternal(JsonConvert.ToString(value), JsonToken.Integer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -426,7 +427,7 @@ namespace Newtonsoft.Json
|
|||||||
/// <param name="value">The <see cref="Decimal"/> value to write.</param>
|
/// <param name="value">The <see cref="Decimal"/> value to write.</param>
|
||||||
public override void WriteValue(decimal value)
|
public override void WriteValue(decimal value)
|
||||||
{
|
{
|
||||||
base.WriteValue(value);
|
InternalWriteValue(JsonToken.Float);
|
||||||
WriteValueInternal(JsonConvert.ToString(value), JsonToken.Float);
|
WriteValueInternal(JsonConvert.ToString(value), JsonToken.Float);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -436,7 +437,7 @@ namespace Newtonsoft.Json
|
|||||||
/// <param name="value">The <see cref="DateTime"/> value to write.</param>
|
/// <param name="value">The <see cref="DateTime"/> value to write.</param>
|
||||||
public override void WriteValue(DateTime value)
|
public override void WriteValue(DateTime value)
|
||||||
{
|
{
|
||||||
base.WriteValue(value);
|
InternalWriteValue(JsonToken.Date);
|
||||||
value = JsonConvert.EnsureDateTime(value, DateTimeZoneHandling);
|
value = JsonConvert.EnsureDateTime(value, DateTimeZoneHandling);
|
||||||
JsonConvert.WriteDateTimeString(_writer, value, DateFormatHandling);
|
JsonConvert.WriteDateTimeString(_writer, value, DateFormatHandling);
|
||||||
}
|
}
|
||||||
@@ -447,10 +448,13 @@ namespace Newtonsoft.Json
|
|||||||
/// <param name="value">The <see cref="T:Byte[]"/> value to write.</param>
|
/// <param name="value">The <see cref="T:Byte[]"/> value to write.</param>
|
||||||
public override void WriteValue(byte[] value)
|
public override void WriteValue(byte[] value)
|
||||||
{
|
{
|
||||||
base.WriteValue(value);
|
if (value == null)
|
||||||
|
|
||||||
if (value != null)
|
|
||||||
{
|
{
|
||||||
|
WriteNull();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
InternalWriteValue(JsonToken.Bytes);
|
||||||
_writer.Write(_quoteChar);
|
_writer.Write(_quoteChar);
|
||||||
Base64Encoder.Encode(value, 0, value.Length);
|
Base64Encoder.Encode(value, 0, value.Length);
|
||||||
Base64Encoder.Flush();
|
Base64Encoder.Flush();
|
||||||
@@ -465,7 +469,7 @@ namespace Newtonsoft.Json
|
|||||||
/// <param name="value">The <see cref="DateTimeOffset"/> value to write.</param>
|
/// <param name="value">The <see cref="DateTimeOffset"/> value to write.</param>
|
||||||
public override void WriteValue(DateTimeOffset value)
|
public override void WriteValue(DateTimeOffset value)
|
||||||
{
|
{
|
||||||
base.WriteValue(value);
|
InternalWriteValue(JsonToken.Date);
|
||||||
WriteValueInternal(JsonConvert.ToString(value, DateFormatHandling), JsonToken.Date);
|
WriteValueInternal(JsonConvert.ToString(value, DateFormatHandling), JsonToken.Date);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -476,7 +480,7 @@ namespace Newtonsoft.Json
|
|||||||
/// <param name="value">The <see cref="Guid"/> value to write.</param>
|
/// <param name="value">The <see cref="Guid"/> value to write.</param>
|
||||||
public override void WriteValue(Guid value)
|
public override void WriteValue(Guid value)
|
||||||
{
|
{
|
||||||
base.WriteValue(value);
|
InternalWriteValue(JsonToken.String);
|
||||||
WriteValueInternal(JsonConvert.ToString(value), JsonToken.String);
|
WriteValueInternal(JsonConvert.ToString(value), JsonToken.String);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -486,7 +490,7 @@ namespace Newtonsoft.Json
|
|||||||
/// <param name="value">The <see cref="TimeSpan"/> value to write.</param>
|
/// <param name="value">The <see cref="TimeSpan"/> value to write.</param>
|
||||||
public override void WriteValue(TimeSpan value)
|
public override void WriteValue(TimeSpan value)
|
||||||
{
|
{
|
||||||
base.WriteValue(value);
|
InternalWriteValue(JsonToken.String);
|
||||||
WriteValueInternal(JsonConvert.ToString(value), JsonToken.String);
|
WriteValueInternal(JsonConvert.ToString(value), JsonToken.String);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -496,8 +500,15 @@ namespace Newtonsoft.Json
|
|||||||
/// <param name="value">The <see cref="Uri"/> value to write.</param>
|
/// <param name="value">The <see cref="Uri"/> value to write.</param>
|
||||||
public override void WriteValue(Uri value)
|
public override void WriteValue(Uri value)
|
||||||
{
|
{
|
||||||
base.WriteValue(value);
|
if (value == null)
|
||||||
WriteValueInternal(JsonConvert.ToString(value), JsonToken.String);
|
{
|
||||||
|
WriteNull();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
InternalWriteValue(JsonToken.String);
|
||||||
|
WriteValueInternal(JsonConvert.ToString(value), JsonToken.String);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -507,7 +518,7 @@ namespace Newtonsoft.Json
|
|||||||
/// <param name="text">Text to place inside the comment.</param>
|
/// <param name="text">Text to place inside the comment.</param>
|
||||||
public override void WriteComment(string text)
|
public override void WriteComment(string text)
|
||||||
{
|
{
|
||||||
base.WriteComment(text);
|
InternalWriteComment();
|
||||||
|
|
||||||
_writer.Write("/*");
|
_writer.Write("/*");
|
||||||
_writer.Write(text);
|
_writer.Write(text);
|
||||||
@@ -520,7 +531,7 @@ namespace Newtonsoft.Json
|
|||||||
/// <param name="ws">The string of white space characters.</param>
|
/// <param name="ws">The string of white space characters.</param>
|
||||||
public override void WriteWhitespace(string ws)
|
public override void WriteWhitespace(string ws)
|
||||||
{
|
{
|
||||||
base.WriteWhitespace(ws);
|
InternalWriteWhitespace(ws);
|
||||||
|
|
||||||
_writer.Write(ws);
|
_writer.Write(ws);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,7 +54,6 @@ namespace Newtonsoft.Json
|
|||||||
Array,
|
Array,
|
||||||
ConstructorStart,
|
ConstructorStart,
|
||||||
Constructor,
|
Constructor,
|
||||||
Bytes,
|
|
||||||
Closed,
|
Closed,
|
||||||
Error
|
Error
|
||||||
}
|
}
|
||||||
@@ -69,7 +68,7 @@ namespace Newtonsoft.Json
|
|||||||
/* StartObject */new[]{ State.ObjectStart, State.ObjectStart, State.Error, State.Error, State.ObjectStart, State.ObjectStart, State.ObjectStart, State.ObjectStart, State.Error, State.Error },
|
/* StartObject */new[]{ State.ObjectStart, State.ObjectStart, State.Error, State.Error, State.ObjectStart, State.ObjectStart, State.ObjectStart, State.ObjectStart, State.Error, State.Error },
|
||||||
/* StartArray */new[]{ State.ArrayStart, State.ArrayStart, State.Error, State.Error, State.ArrayStart, State.ArrayStart, State.ArrayStart, State.ArrayStart, State.Error, State.Error },
|
/* StartArray */new[]{ State.ArrayStart, State.ArrayStart, State.Error, State.Error, State.ArrayStart, State.ArrayStart, State.ArrayStart, State.ArrayStart, State.Error, State.Error },
|
||||||
/* StartConstructor */new[]{ State.ConstructorStart, State.ConstructorStart, State.Error, State.Error, State.ConstructorStart, State.ConstructorStart, State.ConstructorStart, State.ConstructorStart, State.Error, State.Error },
|
/* StartConstructor */new[]{ State.ConstructorStart, State.ConstructorStart, State.Error, State.Error, State.ConstructorStart, State.ConstructorStart, State.ConstructorStart, State.ConstructorStart, State.Error, State.Error },
|
||||||
/* StartProperty */new[]{ State.Property, State.Error, State.Property, State.Property, State.Error, State.Error, State.Error, State.Error, State.Error, State.Error },
|
/* Property */new[]{ State.Property, State.Error, State.Property, State.Property, State.Error, State.Error, State.Error, State.Error, State.Error, State.Error },
|
||||||
/* Comment */new[]{ State.Start, State.Property, State.ObjectStart, State.Object, State.ArrayStart, State.Array, State.Constructor, State.Constructor, State.Error, State.Error },
|
/* Comment */new[]{ State.Start, State.Property, State.ObjectStart, State.Object, State.ArrayStart, State.Array, State.Constructor, State.Constructor, State.Error, State.Error },
|
||||||
/* Raw */new[]{ State.Start, State.Property, State.ObjectStart, State.Object, State.ArrayStart, State.Array, State.Constructor, State.Constructor, State.Error, State.Error },
|
/* Raw */new[]{ State.Start, State.Property, State.ObjectStart, State.Object, State.ArrayStart, State.Array, State.Constructor, State.Constructor, State.Error, State.Error },
|
||||||
/* Value (this will be copied) */new[]{ State.Start, State.Object, State.Error, State.Error, State.Array, State.Array, State.Constructor, State.Constructor, State.Error, State.Error }
|
/* Value (this will be copied) */new[]{ State.Start, State.Object, State.Error, State.Error, State.Array, State.Array, State.Constructor, State.Constructor, State.Error, State.Error }
|
||||||
@@ -142,7 +141,7 @@ namespace Newtonsoft.Json
|
|||||||
return depth;
|
return depth;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the state of the writer.
|
/// Gets the state of the writer.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -304,10 +303,15 @@ namespace Newtonsoft.Json
|
|||||||
/// Writes the beginning of a Json object.
|
/// Writes the beginning of a Json object.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual void WriteStartObject()
|
public virtual void WriteStartObject()
|
||||||
|
{
|
||||||
|
InternalWriteStart(JsonToken.StartObject, JsonContainerType.Object);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void InternalWriteStart(JsonToken token, JsonContainerType container)
|
||||||
{
|
{
|
||||||
UpdateScopeWithFinishedValue();
|
UpdateScopeWithFinishedValue();
|
||||||
AutoComplete(JsonToken.StartObject);
|
AutoComplete(token);
|
||||||
Push(JsonContainerType.Object);
|
Push(container);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -315,7 +319,7 @@ namespace Newtonsoft.Json
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual void WriteEndObject()
|
public virtual void WriteEndObject()
|
||||||
{
|
{
|
||||||
AutoCompleteClose(JsonContainerType.Object);
|
InternalWriteEnd(JsonContainerType.Object);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -323,9 +327,7 @@ namespace Newtonsoft.Json
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual void WriteStartArray()
|
public virtual void WriteStartArray()
|
||||||
{
|
{
|
||||||
UpdateScopeWithFinishedValue();
|
InternalWriteStart(JsonToken.StartArray, JsonContainerType.Array);
|
||||||
AutoComplete(JsonToken.StartArray);
|
|
||||||
Push(JsonContainerType.Array);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -333,7 +335,7 @@ namespace Newtonsoft.Json
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual void WriteEndArray()
|
public virtual void WriteEndArray()
|
||||||
{
|
{
|
||||||
AutoCompleteClose(JsonContainerType.Array);
|
InternalWriteEnd(JsonContainerType.Array);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -342,9 +344,7 @@ namespace Newtonsoft.Json
|
|||||||
/// <param name="name">The name of the constructor.</param>
|
/// <param name="name">The name of the constructor.</param>
|
||||||
public virtual void WriteStartConstructor(string name)
|
public virtual void WriteStartConstructor(string name)
|
||||||
{
|
{
|
||||||
UpdateScopeWithFinishedValue();
|
InternalWriteStart(JsonToken.StartConstructor, JsonContainerType.Constructor);
|
||||||
AutoComplete(JsonToken.StartConstructor);
|
|
||||||
Push(JsonContainerType.Constructor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -352,7 +352,12 @@ namespace Newtonsoft.Json
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual void WriteEndConstructor()
|
public virtual void WriteEndConstructor()
|
||||||
{
|
{
|
||||||
AutoCompleteClose(JsonContainerType.Constructor);
|
InternalWriteEnd(JsonContainerType.Constructor);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void InternalWriteEnd(JsonContainerType container)
|
||||||
|
{
|
||||||
|
AutoCompleteClose(container);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -360,6 +365,11 @@ namespace Newtonsoft.Json
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="name">The name of the property.</param>
|
/// <param name="name">The name of the property.</param>
|
||||||
public virtual void WritePropertyName(string name)
|
public virtual void WritePropertyName(string name)
|
||||||
|
{
|
||||||
|
InternalWritePropertyName(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void InternalWritePropertyName(string name)
|
||||||
{
|
{
|
||||||
_currentPosition.PropertyName = name;
|
_currentPosition.PropertyName = name;
|
||||||
AutoComplete(JsonToken.PropertyName);
|
AutoComplete(JsonToken.PropertyName);
|
||||||
@@ -672,22 +682,16 @@ namespace Newtonsoft.Json
|
|||||||
{
|
{
|
||||||
WriteValueDelimiter();
|
WriteValueDelimiter();
|
||||||
}
|
}
|
||||||
else if (_currentState == State.Property)
|
|
||||||
{
|
|
||||||
if (_formatting == Formatting.Indented)
|
|
||||||
WriteIndentSpace();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_formatting == Formatting.Indented)
|
if (_formatting == Formatting.Indented)
|
||||||
{
|
{
|
||||||
WriteState writeState = WriteState;
|
if (_currentState == State.Property)
|
||||||
|
WriteIndentSpace();
|
||||||
|
|
||||||
// don't indent a property when it is the first token to be written (i.e. at the start)
|
// don't indent a property when it is the first token to be written (i.e. at the start)
|
||||||
if ((tokenBeingWritten == JsonToken.PropertyName && writeState != WriteState.Start) ||
|
if ((_currentState == State.Array || _currentState == State.ArrayStart || _currentState == State.Constructor || _currentState == State.ConstructorStart)
|
||||||
writeState == WriteState.Array || writeState == WriteState.Constructor)
|
|| (tokenBeingWritten == JsonToken.PropertyName && _currentState != State.Start))
|
||||||
{
|
|
||||||
WriteIndent();
|
WriteIndent();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_currentState = newState;
|
_currentState = newState;
|
||||||
@@ -698,6 +702,11 @@ namespace Newtonsoft.Json
|
|||||||
/// Writes a null value.
|
/// Writes a null value.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual void WriteNull()
|
public virtual void WriteNull()
|
||||||
|
{
|
||||||
|
InternalWriteNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void InternalWriteNull()
|
||||||
{
|
{
|
||||||
UpdateScopeWithFinishedValue();
|
UpdateScopeWithFinishedValue();
|
||||||
AutoComplete(JsonToken.Null);
|
AutoComplete(JsonToken.Null);
|
||||||
@@ -707,6 +716,11 @@ namespace Newtonsoft.Json
|
|||||||
/// Writes an undefined value.
|
/// Writes an undefined value.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual void WriteUndefined()
|
public virtual void WriteUndefined()
|
||||||
|
{
|
||||||
|
InternalWriteUndefined();
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void InternalWriteUndefined()
|
||||||
{
|
{
|
||||||
UpdateScopeWithFinishedValue();
|
UpdateScopeWithFinishedValue();
|
||||||
AutoComplete(JsonToken.Undefined);
|
AutoComplete(JsonToken.Undefined);
|
||||||
@@ -717,6 +731,11 @@ namespace Newtonsoft.Json
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="json">The raw JSON to write.</param>
|
/// <param name="json">The raw JSON to write.</param>
|
||||||
public virtual void WriteRaw(string json)
|
public virtual void WriteRaw(string json)
|
||||||
|
{
|
||||||
|
InternalWriteRaw();
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void InternalWriteRaw()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -737,9 +756,14 @@ namespace Newtonsoft.Json
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="value">The <see cref="String"/> value to write.</param>
|
/// <param name="value">The <see cref="String"/> value to write.</param>
|
||||||
public virtual void WriteValue(string value)
|
public virtual void WriteValue(string value)
|
||||||
|
{
|
||||||
|
InternalWriteValue(JsonToken.String);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void InternalWriteValue(JsonToken token)
|
||||||
{
|
{
|
||||||
UpdateScopeWithFinishedValue();
|
UpdateScopeWithFinishedValue();
|
||||||
AutoComplete(JsonToken.String);
|
AutoComplete(token);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -748,8 +772,7 @@ namespace Newtonsoft.Json
|
|||||||
/// <param name="value">The <see cref="Int32"/> value to write.</param>
|
/// <param name="value">The <see cref="Int32"/> value to write.</param>
|
||||||
public virtual void WriteValue(int value)
|
public virtual void WriteValue(int value)
|
||||||
{
|
{
|
||||||
UpdateScopeWithFinishedValue();
|
InternalWriteValue(JsonToken.Integer);
|
||||||
AutoComplete(JsonToken.Integer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -759,8 +782,7 @@ namespace Newtonsoft.Json
|
|||||||
[CLSCompliant(false)]
|
[CLSCompliant(false)]
|
||||||
public virtual void WriteValue(uint value)
|
public virtual void WriteValue(uint value)
|
||||||
{
|
{
|
||||||
UpdateScopeWithFinishedValue();
|
InternalWriteValue(JsonToken.Integer);
|
||||||
AutoComplete(JsonToken.Integer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -769,8 +791,7 @@ namespace Newtonsoft.Json
|
|||||||
/// <param name="value">The <see cref="Int64"/> value to write.</param>
|
/// <param name="value">The <see cref="Int64"/> value to write.</param>
|
||||||
public virtual void WriteValue(long value)
|
public virtual void WriteValue(long value)
|
||||||
{
|
{
|
||||||
UpdateScopeWithFinishedValue();
|
InternalWriteValue(JsonToken.Integer);
|
||||||
AutoComplete(JsonToken.Integer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -780,8 +801,7 @@ namespace Newtonsoft.Json
|
|||||||
[CLSCompliant(false)]
|
[CLSCompliant(false)]
|
||||||
public virtual void WriteValue(ulong value)
|
public virtual void WriteValue(ulong value)
|
||||||
{
|
{
|
||||||
UpdateScopeWithFinishedValue();
|
InternalWriteValue(JsonToken.Integer);
|
||||||
AutoComplete(JsonToken.Integer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -790,8 +810,7 @@ namespace Newtonsoft.Json
|
|||||||
/// <param name="value">The <see cref="Single"/> value to write.</param>
|
/// <param name="value">The <see cref="Single"/> value to write.</param>
|
||||||
public virtual void WriteValue(float value)
|
public virtual void WriteValue(float value)
|
||||||
{
|
{
|
||||||
UpdateScopeWithFinishedValue();
|
InternalWriteValue(JsonToken.Float);
|
||||||
AutoComplete(JsonToken.Float);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -800,8 +819,7 @@ namespace Newtonsoft.Json
|
|||||||
/// <param name="value">The <see cref="Double"/> value to write.</param>
|
/// <param name="value">The <see cref="Double"/> value to write.</param>
|
||||||
public virtual void WriteValue(double value)
|
public virtual void WriteValue(double value)
|
||||||
{
|
{
|
||||||
UpdateScopeWithFinishedValue();
|
InternalWriteValue(JsonToken.Float);
|
||||||
AutoComplete(JsonToken.Float);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -810,8 +828,7 @@ namespace Newtonsoft.Json
|
|||||||
/// <param name="value">The <see cref="Boolean"/> value to write.</param>
|
/// <param name="value">The <see cref="Boolean"/> value to write.</param>
|
||||||
public virtual void WriteValue(bool value)
|
public virtual void WriteValue(bool value)
|
||||||
{
|
{
|
||||||
UpdateScopeWithFinishedValue();
|
InternalWriteValue(JsonToken.Boolean);
|
||||||
AutoComplete(JsonToken.Boolean);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -820,8 +837,7 @@ namespace Newtonsoft.Json
|
|||||||
/// <param name="value">The <see cref="Int16"/> value to write.</param>
|
/// <param name="value">The <see cref="Int16"/> value to write.</param>
|
||||||
public virtual void WriteValue(short value)
|
public virtual void WriteValue(short value)
|
||||||
{
|
{
|
||||||
UpdateScopeWithFinishedValue();
|
InternalWriteValue(JsonToken.Integer);
|
||||||
AutoComplete(JsonToken.Integer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -831,8 +847,7 @@ namespace Newtonsoft.Json
|
|||||||
[CLSCompliant(false)]
|
[CLSCompliant(false)]
|
||||||
public virtual void WriteValue(ushort value)
|
public virtual void WriteValue(ushort value)
|
||||||
{
|
{
|
||||||
UpdateScopeWithFinishedValue();
|
InternalWriteValue(JsonToken.Integer);
|
||||||
AutoComplete(JsonToken.Integer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -841,8 +856,7 @@ namespace Newtonsoft.Json
|
|||||||
/// <param name="value">The <see cref="Char"/> value to write.</param>
|
/// <param name="value">The <see cref="Char"/> value to write.</param>
|
||||||
public virtual void WriteValue(char value)
|
public virtual void WriteValue(char value)
|
||||||
{
|
{
|
||||||
UpdateScopeWithFinishedValue();
|
InternalWriteValue(JsonToken.String);
|
||||||
AutoComplete(JsonToken.String);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -851,8 +865,7 @@ namespace Newtonsoft.Json
|
|||||||
/// <param name="value">The <see cref="Byte"/> value to write.</param>
|
/// <param name="value">The <see cref="Byte"/> value to write.</param>
|
||||||
public virtual void WriteValue(byte value)
|
public virtual void WriteValue(byte value)
|
||||||
{
|
{
|
||||||
UpdateScopeWithFinishedValue();
|
InternalWriteValue(JsonToken.Integer);
|
||||||
AutoComplete(JsonToken.Integer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -862,8 +875,7 @@ namespace Newtonsoft.Json
|
|||||||
[CLSCompliant(false)]
|
[CLSCompliant(false)]
|
||||||
public virtual void WriteValue(sbyte value)
|
public virtual void WriteValue(sbyte value)
|
||||||
{
|
{
|
||||||
UpdateScopeWithFinishedValue();
|
InternalWriteValue(JsonToken.Integer);
|
||||||
AutoComplete(JsonToken.Integer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -872,8 +884,7 @@ namespace Newtonsoft.Json
|
|||||||
/// <param name="value">The <see cref="Decimal"/> value to write.</param>
|
/// <param name="value">The <see cref="Decimal"/> value to write.</param>
|
||||||
public virtual void WriteValue(decimal value)
|
public virtual void WriteValue(decimal value)
|
||||||
{
|
{
|
||||||
UpdateScopeWithFinishedValue();
|
InternalWriteValue(JsonToken.Float);
|
||||||
AutoComplete(JsonToken.Float);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -882,8 +893,7 @@ namespace Newtonsoft.Json
|
|||||||
/// <param name="value">The <see cref="DateTime"/> value to write.</param>
|
/// <param name="value">The <see cref="DateTime"/> value to write.</param>
|
||||||
public virtual void WriteValue(DateTime value)
|
public virtual void WriteValue(DateTime value)
|
||||||
{
|
{
|
||||||
UpdateScopeWithFinishedValue();
|
InternalWriteValue(JsonToken.Date);
|
||||||
AutoComplete(JsonToken.Date);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !PocketPC && !NET20
|
#if !PocketPC && !NET20
|
||||||
@@ -893,8 +903,7 @@ namespace Newtonsoft.Json
|
|||||||
/// <param name="value">The <see cref="DateTimeOffset"/> value to write.</param>
|
/// <param name="value">The <see cref="DateTimeOffset"/> value to write.</param>
|
||||||
public virtual void WriteValue(DateTimeOffset value)
|
public virtual void WriteValue(DateTimeOffset value)
|
||||||
{
|
{
|
||||||
UpdateScopeWithFinishedValue();
|
InternalWriteValue(JsonToken.Date);
|
||||||
AutoComplete(JsonToken.Date);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -904,8 +913,7 @@ namespace Newtonsoft.Json
|
|||||||
/// <param name="value">The <see cref="Guid"/> value to write.</param>
|
/// <param name="value">The <see cref="Guid"/> value to write.</param>
|
||||||
public virtual void WriteValue(Guid value)
|
public virtual void WriteValue(Guid value)
|
||||||
{
|
{
|
||||||
UpdateScopeWithFinishedValue();
|
InternalWriteValue(JsonToken.String);
|
||||||
AutoComplete(JsonToken.String);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -914,8 +922,7 @@ namespace Newtonsoft.Json
|
|||||||
/// <param name="value">The <see cref="TimeSpan"/> value to write.</param>
|
/// <param name="value">The <see cref="TimeSpan"/> value to write.</param>
|
||||||
public virtual void WriteValue(TimeSpan value)
|
public virtual void WriteValue(TimeSpan value)
|
||||||
{
|
{
|
||||||
UpdateScopeWithFinishedValue();
|
InternalWriteValue(JsonToken.String);
|
||||||
AutoComplete(JsonToken.String);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -1135,14 +1142,9 @@ namespace Newtonsoft.Json
|
|||||||
public virtual void WriteValue(byte[] value)
|
public virtual void WriteValue(byte[] value)
|
||||||
{
|
{
|
||||||
if (value == null)
|
if (value == null)
|
||||||
{
|
|
||||||
WriteNull();
|
WriteNull();
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
InternalWriteValue(JsonToken.Bytes);
|
||||||
UpdateScopeWithFinishedValue();
|
|
||||||
AutoComplete(JsonToken.Bytes);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -1152,14 +1154,9 @@ namespace Newtonsoft.Json
|
|||||||
public virtual void WriteValue(Uri value)
|
public virtual void WriteValue(Uri value)
|
||||||
{
|
{
|
||||||
if (value == null)
|
if (value == null)
|
||||||
{
|
|
||||||
WriteNull();
|
WriteNull();
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
InternalWriteValue(JsonToken.String);
|
||||||
UpdateScopeWithFinishedValue();
|
|
||||||
AutoComplete(JsonToken.String);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -1270,7 +1267,11 @@ namespace Newtonsoft.Json
|
|||||||
/// <param name="text">Text to place inside the comment.</param>
|
/// <param name="text">Text to place inside the comment.</param>
|
||||||
public virtual void WriteComment(string text)
|
public virtual void WriteComment(string text)
|
||||||
{
|
{
|
||||||
UpdateScopeWithFinishedValue();
|
InternalWriteComment();
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void InternalWriteComment()
|
||||||
|
{
|
||||||
AutoComplete(JsonToken.Comment);
|
AutoComplete(JsonToken.Comment);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1279,6 +1280,11 @@ namespace Newtonsoft.Json
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="ws">The string of white space characters.</param>
|
/// <param name="ws">The string of white space characters.</param>
|
||||||
public virtual void WriteWhitespace(string ws)
|
public virtual void WriteWhitespace(string ws)
|
||||||
|
{
|
||||||
|
InternalWriteWhitespace(ws);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void InternalWriteWhitespace(string ws)
|
||||||
{
|
{
|
||||||
if (ws != null)
|
if (ws != null)
|
||||||
{
|
{
|
||||||
@@ -1287,7 +1293,6 @@ namespace Newtonsoft.Json
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void IDisposable.Dispose()
|
void IDisposable.Dispose()
|
||||||
{
|
{
|
||||||
Dispose(true);
|
Dispose(true);
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ using System.Security;
|
|||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
[assembly: AssemblyVersion("4.5.0.0")]
|
[assembly: AssemblyVersion("4.5.0.0")]
|
||||||
#if !PocketPC
|
#if !PocketPC
|
||||||
[assembly: AssemblyFileVersion("4.5.10.15427")]
|
[assembly: AssemblyFileVersion("4.5.10.15501")]
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
[assembly: CLSCompliant(true)]
|
[assembly: CLSCompliant(true)]
|
||||||
|
|||||||
Reference in New Issue
Block a user