From 9eca136e792849ef8b85dd1ddb0c7609a6fc82e1 Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Thu, 2 Apr 2015 20:16:33 +1300 Subject: [PATCH] -Documentation --- .../ReadMultipleContentWithJsonReader.aml | 17 ++++ Doc/SerializationAttributes.aml | 16 +++- Doc/doc.content | 9 +- Doc/doc.shfbproj | 1 + .../Properties/AssemblyInfo.cs | 2 +- .../Json/ReadMultipleContentWithJsonReader.cs | 90 +++++++++++++++++++ .../Newtonsoft.Json.Tests.csproj | 1 + .../Properties/AssemblyInfo.cs | 2 +- .../Properties/AssemblyInfo.cs | 2 +- 9 files changed, 130 insertions(+), 10 deletions(-) create mode 100644 Doc/Samples/Json/ReadMultipleContentWithJsonReader.aml create mode 100644 Src/Newtonsoft.Json.Tests/Documentation/Samples/Json/ReadMultipleContentWithJsonReader.cs diff --git a/Doc/Samples/Json/ReadMultipleContentWithJsonReader.aml b/Doc/Samples/Json/ReadMultipleContentWithJsonReader.aml new file mode 100644 index 00000000..1556fbd8 --- /dev/null +++ b/Doc/Samples/Json/ReadMultipleContentWithJsonReader.aml @@ -0,0 +1,17 @@ + + + + + This sample sets P:Newtonsoft.Json.JsonReader.SupportMultipleContent + to true so that multiple JSON fragments can be read from a T:System.IO.Stream or + T:System.IO.TextReader. + +
+ Sample + + + + +
+
+
\ No newline at end of file diff --git a/Doc/SerializationAttributes.aml b/Doc/SerializationAttributes.aml index e4bac083..b88a98b7 100644 --- a/Doc/SerializationAttributes.aml +++ b/Doc/SerializationAttributes.aml @@ -20,6 +20,7 @@ T:Newtonsoft.Json.JsonDictionaryAttribute - Placed on dictionaries to control how they should be serialized as a JSON object. T:Newtonsoft.Json.JsonPropertyAttribute - Placed on fields and properties to control how they should be serialized as a property in a JSON object. T:Newtonsoft.Json.JsonConverterAttribute - Placed on either classes or fields and properties to specify which JsonConverter should be used during serialization. + T:Newtonsoft.Json.JsonExtensionDataAttribute - Placed on a collection field or property to deserialize properties with no matching class member into the specified collection and write values during serialization. @@ -101,10 +102,8 @@
JsonIgnoreAttribute - Excludes a field or property from serialization. - The T:System.NonSerializedAttribute can be used as substitute for JsonIgnoreAttribute. + The T:System.NonSerializedAttribute can be used as a substitute for JsonIgnoreAttribute.
@@ -132,6 +131,17 @@ and set the ItemConverterType property to the converter type you want to use. + +
+ JsonExtensionDataAttribute + + Instructs the T:Newtonsoft.Json.JsonSerializer to deserialize properties with no matching class member + into the specified collection and write values during serialization. + + + +
+ diff --git a/Doc/doc.content b/Doc/doc.content index 901ae13e..d57463b9 100644 --- a/Doc/doc.content +++ b/Doc/doc.content @@ -30,7 +30,7 @@ - + @@ -82,7 +82,7 @@ - + @@ -90,7 +90,7 @@ - + @@ -150,9 +150,10 @@ - + + diff --git a/Doc/doc.shfbproj b/Doc/doc.shfbproj index 1f39bf5d..b7fa3ebd 100644 --- a/Doc/doc.shfbproj +++ b/Doc/doc.shfbproj @@ -100,6 +100,7 @@ + diff --git a/Src/Newtonsoft.Json.TestConsole/Properties/AssemblyInfo.cs b/Src/Newtonsoft.Json.TestConsole/Properties/AssemblyInfo.cs index 0b37d9bb..9c9dcc51 100644 --- a/Src/Newtonsoft.Json.TestConsole/Properties/AssemblyInfo.cs +++ b/Src/Newtonsoft.Json.TestConsole/Properties/AssemblyInfo.cs @@ -57,4 +57,4 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: [assembly: AssemblyVersion("7.0.0.0")] -[assembly: AssemblyFileVersion("7.0.1.18329")] +[assembly: AssemblyFileVersion("7.0.1.18402")] diff --git a/Src/Newtonsoft.Json.Tests/Documentation/Samples/Json/ReadMultipleContentWithJsonReader.cs b/Src/Newtonsoft.Json.Tests/Documentation/Samples/Json/ReadMultipleContentWithJsonReader.cs new file mode 100644 index 00000000..0a0362d0 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/Documentation/Samples/Json/ReadMultipleContentWithJsonReader.cs @@ -0,0 +1,90 @@ +#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 + +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; + +#if NETFX_CORE +using Microsoft.VisualStudio.TestPlatform.UnitTestFramework; +using TestFixture = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestClassAttribute; +using Test = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestMethodAttribute; +#elif ASPNETCORE50 +using Xunit; +using Test = Xunit.FactAttribute; +using Assert = Newtonsoft.Json.Tests.XUnitAssert; +#else +using NUnit.Framework; +#endif + +namespace Newtonsoft.Json.Tests.Documentation.Samples.Json +{ + public class ReadMultipleContentWithJsonReader + { + #region Types + public class Role + { + public string Name { get; set; } + } + #endregion + + public void Example() + { + #region Usage + string json = @"{ 'name': 'Admin' }{ 'name': 'Publisher' }"; + + IList roles = new List(); + + JsonTextReader reader = new JsonTextReader(new StringReader(json)); + reader.SupportMultipleContent = true; + + while (true) + { + if (!reader.Read()) + break; + + JsonSerializer serializer = new JsonSerializer(); + Role role = serializer.Deserialize(reader); + + roles.Add(role); + } + + foreach (Role role in roles) + { + Console.WriteLine(role.Name); + } + + // Admin + // Publisher + #endregion + + Assert.AreEqual(2, roles.Count); + Assert.AreEqual("Admin", roles[0].Name); + Assert.AreEqual("Publisher", roles[1].Name); + } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.csproj b/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.csproj index 177652c4..0ed270aa 100644 --- a/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.csproj +++ b/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.csproj @@ -93,6 +93,7 @@ + diff --git a/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs b/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs index 34825fb8..a2c90e25 100644 --- a/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs +++ b/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs @@ -76,4 +76,4 @@ using System.Security; // by using the '*' as shown below: [assembly: AssemblyVersion("7.0.0.0")] -[assembly: AssemblyFileVersion("7.0.1.18329")] +[assembly: AssemblyFileVersion("7.0.1.18402")] diff --git a/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs b/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs index 183100aa..fdd58ec9 100644 --- a/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs +++ b/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs @@ -92,5 +92,5 @@ using System.Security; // by using the '*' as shown below: [assembly: AssemblyVersion("7.0.0.0")] -[assembly: AssemblyFileVersion("7.0.1.18329")] +[assembly: AssemblyFileVersion("7.0.1.18402")] [assembly: CLSCompliant(true)]