From 49328ddeb0e58a7419c25b69d4932b9886886073 Mon Sep 17 00:00:00 2001 From: JamesNK Date: Fri, 10 Feb 2012 11:33:45 +0000 Subject: [PATCH] -Incremented version to 4.0.8 -Added VersionConverter -Fixed converting XML to JSON with a default namespace -Changed Silverlight/Windows Phone assemblies to not be signed --- Build/Newtonsoft.Json.nuspec | 2 +- Build/build.ps1 | 40 +- Doc/versions.txt | 6 +- .../Converters/VersionConverterTests.cs | 114 ++++ .../Converters/XmlNodeConverterTest.cs | 490 +++++++++++++++++- .../JsonTextReaderTest.cs | 10 + .../Newtonsoft.Json.Tests.Net20.csproj | 1 + .../Newtonsoft.Json.Tests.Net35.csproj | 1 + .../Newtonsoft.Json.Tests.Silverlight.csproj | 1 + .../Newtonsoft.Json.Tests.WindowsPhone.csproj | 1 + .../Newtonsoft.Json.Tests.csproj | 1 + .../Properties/AssemblyInfo.cs | 24 +- .../Converters/VersionConverter.cs | 109 ++++ .../Converters/XmlNodeConverter.cs | 8 +- .../Newtonsoft.Json.Net20.csproj | 1 + .../Newtonsoft.Json.Net35.csproj | 1 + .../Newtonsoft.Json.Silverlight.csproj | 1 + .../Newtonsoft.Json.WindowsPhone.csproj | 1 + Src/Newtonsoft.Json/Newtonsoft.Json.csproj | 1 + .../Properties/AssemblyInfo.cs | 22 +- 20 files changed, 777 insertions(+), 58 deletions(-) create mode 100644 Src/Newtonsoft.Json.Tests/Converters/VersionConverterTests.cs create mode 100644 Src/Newtonsoft.Json/Converters/VersionConverter.cs diff --git a/Build/Newtonsoft.Json.nuspec b/Build/Newtonsoft.Json.nuspec index d8b232e3..3495d317 100644 --- a/Build/Newtonsoft.Json.nuspec +++ b/Build/Newtonsoft.Json.nuspec @@ -3,7 +3,7 @@ Newtonsoft.Json Json.NET - 4.0.7 + 4.0.8 James Newton-King Json.NET is a popular high-performance JSON framework for .NET en-US diff --git a/Build/build.ps1 b/Build/build.ps1 index 3a9bee0c..66a61c51 100644 --- a/Build/build.ps1 +++ b/Build/build.ps1 @@ -1,6 +1,6 @@ properties { - $zipFileName = "Json40r7.zip" - $majorVersion = "4.0.7" + $zipFileName = "Json40r8.zip" + $majorVersion = "4.0.8" $version = GetVersion $majorVersion $signAssemblies = $false $signKeyPath = "D:\Development\Releases\newtonsoft.snk" @@ -15,11 +15,11 @@ $releaseDir = "$baseDir\Release" $workingDir = "$baseDir\Working" $builds = @( - @{Name = "Newtonsoft.Json"; TestsName = "Newtonsoft.Json.Tests"; Constants=""; FinalDir="Net"; NuGetDir = "net40"; Framework="net-4.0"}, - @{Name = "Newtonsoft.Json.WindowsPhone"; TestsName = $null; Constants="SILVERLIGHT;WINDOWS_PHONE"; FinalDir="WindowsPhone"; NuGetDir = "sl3-wp,sl4-windowsphone71"; Framework="net-4.0"}, - @{Name = "Newtonsoft.Json.Silverlight"; TestsName = "Newtonsoft.Json.Tests.Silverlight"; Constants="SILVERLIGHT"; FinalDir="Silverlight"; NuGetDir = "sl4"; Framework="net-4.0"}, - @{Name = "Newtonsoft.Json.Net35"; TestsName = "Newtonsoft.Json.Tests.Net35"; Constants="NET35"; FinalDir="Net35"; NuGetDir = "net35"; Framework="net-2.0"}, - @{Name = "Newtonsoft.Json.Net20"; TestsName = "Newtonsoft.Json.Tests.Net20"; Constants="NET20"; FinalDir="Net20"; NuGetDir = "net20"; Framework="net-2.0"} + @{Name = "Newtonsoft.Json"; TestsName = "Newtonsoft.Json.Tests"; Constants=""; FinalDir="Net40"; NuGetDir = "net40"; Framework="net-4.0"; Sign=$true}, + @{Name = "Newtonsoft.Json.WindowsPhone"; TestsName = $null; Constants="SILVERLIGHT;WINDOWS_PHONE"; FinalDir="WindowsPhone"; NuGetDir = "sl3-wp,sl4-windowsphone71"; Framework="net-4.0"; Sign=$false}, + @{Name = "Newtonsoft.Json.Silverlight"; TestsName = "Newtonsoft.Json.Tests.Silverlight"; Constants="SILVERLIGHT"; FinalDir="Silverlight"; NuGetDir = "sl4"; Framework="net-4.0"; Sign=$false}, + @{Name = "Newtonsoft.Json.Net35"; TestsName = "Newtonsoft.Json.Tests.Net35"; Constants="NET35"; FinalDir="Net35"; NuGetDir = "net35"; Framework="net-2.0"; Sign=$true}, + @{Name = "Newtonsoft.Json.Net20"; TestsName = "Newtonsoft.Json.Tests.Net20"; Constants="NET20"; FinalDir="Net20"; NuGetDir = "net20"; Framework="net-2.0"; Sign=$true} ) } @@ -51,10 +51,12 @@ task Build -depends Clean { { $name = $build.Name $finalDir = $build.FinalDir + $sign = ($build.Sign -and $signAssemblies) Write-Host -ForegroundColor Green "Building " $name + Write-Host -ForegroundColor Green "Signed " $sign Write-Host - exec { msbuild "/t:Clean;Rebuild" /p:Configuration=Release /p:OutputPath=bin\Release\$finalDir\ /p:AssemblyOriginatorKeyFile=$signKeyPath "/p:SignAssembly=$signAssemblies" (GetConstants $build.Constants $signAssemblies) ".\Src\$name.sln" } "Error building $name" + exec { msbuild "/t:Clean;Rebuild" /p:Configuration=Release /p:OutputPath=bin\Release\$finalDir\ /p:AssemblyOriginatorKeyFile=$signKeyPath "/p:SignAssembly=$sign" (GetConstants $build.Constants $sign) ".\Src\$name.sln" } "Error building $name" } } @@ -137,28 +139,6 @@ task Test -depends Deploy { } } -function MergeAssembly($dllPrimaryAssembly, $signKey, [string[]]$mergedAssemlies) -{ - $mergeAssemblyPaths = [String]::Join(" ", $mergedAssemlies) - - $primary = Get-Item $dllPrimaryAssembly - $mergedAssemblyName = $primary.Name - $temporaryDir = $primary.DirectoryName + "\" + [Guid]::NewGuid().ToString() - New-Item $temporaryDir -ItemType Directory - - $ilMergeKeyFile = switch($signAssemblies) { $true { "/keyfile:$signKeyPath" } default { "" } } - - try - { - exec { .\Tools\ILMerge\ilmerge.exe "/internalize" "/closed" "/log:$workingDir\$mergedAssemblyName.MergeLog.txt" $ilMergeKeyFile "/out:$temporaryDir\$mergedAssemblyName" $dllPrimaryAssembly $mergeAssemblyPaths } "Error executing ILMerge" - Copy-Item -Path $temporaryDir\$mergedAssemblyName -Destination $dllPrimaryAssembly -Force - } - finally - { - Remove-Item $temporaryDir -Recurse -Force - } -} - function GetConstants($constants, $includeSigned) { $signed = switch($includeSigned) { $true { ";SIGNED" } default { "" } } diff --git a/Doc/versions.txt b/Doc/versions.txt index 8a726fb6..ef8d1d87 100644 --- a/Doc/versions.txt +++ b/Doc/versions.txt @@ -2,13 +2,13 @@ Versions: Json.NET comes in different versions for the various .NET frameworks. --DotNet: +-Net40: .NET latest (4.0) --DotNet35: +-Net35: .NET 3.5 SP1, Mono --DotNet20: +-Net20: .NET 2.0 -Silverlight: diff --git a/Src/Newtonsoft.Json.Tests/Converters/VersionConverterTests.cs b/Src/Newtonsoft.Json.Tests/Converters/VersionConverterTests.cs new file mode 100644 index 00000000..eaaaf941 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/Converters/VersionConverterTests.cs @@ -0,0 +1,114 @@ +#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.Linq; +using System.Text; +using Newtonsoft.Json.Converters; +using NUnit.Framework; +using Newtonsoft.Json.Tests.TestObjects; + +namespace Newtonsoft.Json.Tests.Converters +{ + public class VersionClass + { + public VersionClass(string version1, string version2) + { + this.StringProperty1 = "StringProperty1"; + this.Version1 = new Version(version1); + this.Version2 = new Version(version2); + this.StringProperty2 = "StringProperty2"; + } + + public VersionClass() + { + } + + public string StringProperty1 { get; set; } + public Version Version1 { get; set; } + public Version Version2 { get; set; } + public string StringProperty2 { get; set; } + } + + public class VersionConverterTests : TestFixtureBase + { + private void SerializeVersionClass(string version1, string version2) + { + VersionClass versionClass = new VersionClass(version1, version2); + + string json = JsonConvert.SerializeObject(versionClass, Formatting.Indented, new VersionConverter()); + + string expectedJson = string.Format(@"{{ + ""StringProperty1"": ""StringProperty1"", + ""Version1"": ""{0}"", + ""Version2"": ""{1}"", + ""StringProperty2"": ""StringProperty2"" +}}", version1, version2); + + Assert.AreEqual(expectedJson, json); + } + + [Test] + public void SerializeVersionClass() + { + SerializeVersionClass("1.0.0.0", "2.0.0.0"); + SerializeVersionClass("1.2.0.0", "2.3.0.0"); + SerializeVersionClass("1.2.3.0", "2.3.4.0"); + SerializeVersionClass("1.2.3.4", "2.3.4.5"); + + SerializeVersionClass("1.2", "2.3"); + SerializeVersionClass("1.2.3", "2.3.4"); + SerializeVersionClass("1.2.3.4", "2.3.4.5"); + } + + private void DeserializeVersionClass(string version1, string version2) + { + string json = string.Format(@"{{""StringProperty1"": ""StringProperty1"", ""Version1"": ""{0}"", ""Version2"": ""{1}"", ""StringProperty2"": ""StringProperty2""}}", version1, version2); + Version expectedVersion1 = new Version(version1); + Version expectedVersion2 = new Version(version2); + + VersionClass versionClass = JsonConvert.DeserializeObject(json, new VersionConverter()); + + Assert.AreEqual("StringProperty1", versionClass.StringProperty1); + Assert.AreEqual(expectedVersion1, versionClass.Version1); + Assert.AreEqual(expectedVersion2, versionClass.Version2); + Assert.AreEqual("StringProperty2", versionClass.StringProperty2); + } + + [Test] + public void DeserializeVersionClass() + { + DeserializeVersionClass("1.0.0.0", "2.0.0.0"); + DeserializeVersionClass("1.2.0.0", "2.3.0.0"); + DeserializeVersionClass("1.2.3.0", "2.3.4.0"); + DeserializeVersionClass("1.2.3.4", "2.3.4.5"); + + DeserializeVersionClass("1.2", "2.3"); + DeserializeVersionClass("1.2.3", "2.3.4"); + DeserializeVersionClass("1.2.3.4", "2.3.4.5"); + } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/Converters/XmlNodeConverterTest.cs b/Src/Newtonsoft.Json.Tests/Converters/XmlNodeConverterTest.cs index 4dc32b2b..c672ac5b 100644 --- a/Src/Newtonsoft.Json.Tests/Converters/XmlNodeConverterTest.cs +++ b/Src/Newtonsoft.Json.Tests/Converters/XmlNodeConverterTest.cs @@ -1285,7 +1285,7 @@ namespace Newtonsoft.Json.Tests.Converters Assert.AreEqual(@"", xmlString); } - static void JsonBodyToSoapXml(Stream json, Stream xml) + private static void JsonBodyToSoapXml(Stream json, Stream xml) { Newtonsoft.Json.JsonSerializerSettings settings = new Newtonsoft.Json.JsonSerializerSettings(); settings.Converters.Add(new Newtonsoft.Json.Converters.XmlNodeConverter()); @@ -1301,6 +1301,494 @@ namespace Newtonsoft.Json.Tests.Converters } } } + +#if !NET20 + [Test] + public void DeserializeXNodeDefaultNamespace() + { + string xaml = @" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +"; + + string json = JsonConvert.SerializeXNode(XDocument.Parse(xaml), Formatting.Indented); + + string expectedJson = @"{ + ""Grid"": { + ""@xmlns"": ""http://schemas.microsoft.com/winfx/2006/xaml/presentation"", + ""@xmlns:x"": ""http://schemas.microsoft.com/winfx/2006/xaml"", + ""@xmlns:toolkit"": ""clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"", + ""@Style"": ""{StaticResource trimFormGrid}"", + ""@x:Name"": ""TrimObjectForm"", + ""Grid.ColumnDefinitions"": { + ""ColumnDefinition"": [ + { + ""@Width"": ""63*"" + }, + { + ""@Width"": ""320*"" + } + ] + }, + ""Grid.RowDefinitions"": { + ""@xmlns"": """", + ""RowDefinition"": [ + null, + null, + null, + null, + null, + null, + null, + null + ] + }, + ""TextBox"": [ + { + ""@Style"": ""{StaticResource trimFormGrid_TB}"", + ""@Text"": ""{Binding TypedTitle, Converter={StaticResource trimPropertyConverter}}"", + ""@Name"": ""RecordTypedTitle"", + ""@Grid.Column"": ""1"", + ""@Grid.Row"": ""0"", + ""@xmlns"": """" + }, + { + ""@Style"": ""{StaticResource trimFormGrid_TB}"", + ""@Text"": ""{Binding ExternalReference, Converter={StaticResource trimPropertyConverter}}"", + ""@Name"": ""RecordExternalReference"", + ""@Grid.Column"": ""1"", + ""@Grid.Row"": ""1"", + ""@xmlns"": """" + }, + { + ""@Style"": ""{StaticResource trimFormGrid_TB}"", + ""@Text"": ""{Binding Author, Converter={StaticResource trimPropertyConverter}}"", + ""@Name"": ""RecordAuthor"", + ""@Grid.Column"": ""1"", + ""@Grid.Row"": ""4"", + ""@xmlns"": """" + }, + { + ""@Style"": ""{StaticResource trimFormGrid_TB}"", + ""@Text"": ""{Binding Container, Converter={StaticResource trimPropertyConverter}}"", + ""@Name"": ""RecordContainer"", + ""@Grid.Column"": ""1"", + ""@Grid.Row"": ""5"", + ""@xmlns"": """" + }, + { + ""@Style"": ""{StaticResource trimFormGrid_TB}"", + ""@Text"": ""{Binding IsEnclosed, Converter={StaticResource trimPropertyConverter}}"", + ""@Name"": ""RecordIsEnclosed"", + ""@Grid.Column"": ""1"", + ""@Grid.Row"": ""6"", + ""@xmlns"": """" + }, + { + ""@Style"": ""{StaticResource trimFormGrid_TB}"", + ""@Text"": ""{Binding Assignee, Converter={StaticResource trimPropertyConverter}}"", + ""@Name"": ""RecordAssignee"", + ""@Grid.Column"": ""1"", + ""@Grid.Row"": ""7"", + ""@xmlns"": """" + } + ], + ""toolkit:DatePicker"": [ + { + ""@Style"": ""{StaticResource trimFormGrid_DP}"", + ""@Value"": ""{Binding DateCreated, Converter={StaticResource trimPropertyConverter}}"", + ""@Name"": ""RecordDateCreated"", + ""@Grid.Column"": ""1"", + ""@Grid.Row"": ""2"" + }, + { + ""@Style"": ""{StaticResource trimFormGrid_DP}"", + ""@Value"": ""{Binding DateDue, Converter={StaticResource trimPropertyConverter}}"", + ""@Name"": ""RecordDateDue"", + ""@Grid.Column"": ""1"", + ""@Grid.Row"": ""3"" + } + ], + ""TextBlock"": [ + { + ""@Grid.Column"": ""0"", + ""@Text"": ""Title (Free Text Part)"", + ""@Style"": ""{StaticResource trimFormGrid_LBL}"", + ""@Grid.Row"": ""0"", + ""@xmlns"": """" + }, + { + ""@Grid.Column"": ""0"", + ""@Text"": ""External ID"", + ""@Style"": ""{StaticResource trimFormGrid_LBL}"", + ""@Grid.Row"": ""1"", + ""@xmlns"": """" + }, + { + ""@Grid.Column"": ""0"", + ""@Text"": ""Date Created"", + ""@Style"": ""{StaticResource trimFormGrid_LBL}"", + ""@Grid.Row"": ""2"", + ""@xmlns"": """" + }, + { + ""@Grid.Column"": ""0"", + ""@Text"": ""Date Due"", + ""@Style"": ""{StaticResource trimFormGrid_LBL}"", + ""@Grid.Row"": ""3"", + ""@xmlns"": """" + }, + { + ""@Grid.Column"": ""0"", + ""@Text"": ""Author"", + ""@Style"": ""{StaticResource trimFormGrid_LBL}"", + ""@Grid.Row"": ""4"", + ""@xmlns"": """" + }, + { + ""@Grid.Column"": ""0"", + ""@Text"": ""Container"", + ""@Style"": ""{StaticResource trimFormGrid_LBL}"", + ""@Grid.Row"": ""5"", + ""@xmlns"": """" + }, + { + ""@Grid.Column"": ""0"", + ""@Text"": ""Enclosed?"", + ""@Style"": ""{StaticResource trimFormGrid_LBL}"", + ""@Grid.Row"": ""6"", + ""@xmlns"": """" + }, + { + ""@Grid.Column"": ""0"", + ""@Text"": ""Assignee"", + ""@Style"": ""{StaticResource trimFormGrid_LBL}"", + ""@Grid.Row"": ""7"", + ""@xmlns"": """" + } + ] + } +}"; + + Assert.AreEqual(expectedJson, json); + + XNode node = JsonConvert.DeserializeXNode(json); + + string xaml2 = node.ToString(); + + string expectedXaml = @" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +"; + + Assert.AreEqual(expectedXaml, xaml2); + } +#endif + + [Test] + public void DeserializeXmlNodeDefaultNamespace() + { + string xaml = @" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +"; + + XmlDocument document = new XmlDocument(); + document.LoadXml(xaml); + + string json = JsonConvert.SerializeXmlNode(document, Formatting.Indented); + + string expectedJson = @"{ + ""Grid"": { + ""@xmlns"": ""http://schemas.microsoft.com/winfx/2006/xaml/presentation"", + ""@xmlns:x"": ""http://schemas.microsoft.com/winfx/2006/xaml"", + ""@xmlns:toolkit"": ""clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"", + ""@Style"": ""{StaticResource trimFormGrid}"", + ""@x:Name"": ""TrimObjectForm"", + ""Grid.ColumnDefinitions"": { + ""ColumnDefinition"": [ + { + ""@Width"": ""63*"" + }, + { + ""@Width"": ""320*"" + } + ] + }, + ""Grid.RowDefinitions"": { + ""@xmlns"": """", + ""RowDefinition"": [ + null, + null, + null, + null, + null, + null, + null, + null + ] + }, + ""TextBox"": [ + { + ""@Style"": ""{StaticResource trimFormGrid_TB}"", + ""@Text"": ""{Binding TypedTitle, Converter={StaticResource trimPropertyConverter}}"", + ""@Name"": ""RecordTypedTitle"", + ""@Grid.Column"": ""1"", + ""@Grid.Row"": ""0"", + ""@xmlns"": """" + }, + { + ""@Style"": ""{StaticResource trimFormGrid_TB}"", + ""@Text"": ""{Binding ExternalReference, Converter={StaticResource trimPropertyConverter}}"", + ""@Name"": ""RecordExternalReference"", + ""@Grid.Column"": ""1"", + ""@Grid.Row"": ""1"", + ""@xmlns"": """" + }, + { + ""@Style"": ""{StaticResource trimFormGrid_TB}"", + ""@Text"": ""{Binding Author, Converter={StaticResource trimPropertyConverter}}"", + ""@Name"": ""RecordAuthor"", + ""@Grid.Column"": ""1"", + ""@Grid.Row"": ""4"", + ""@xmlns"": """" + }, + { + ""@Style"": ""{StaticResource trimFormGrid_TB}"", + ""@Text"": ""{Binding Container, Converter={StaticResource trimPropertyConverter}}"", + ""@Name"": ""RecordContainer"", + ""@Grid.Column"": ""1"", + ""@Grid.Row"": ""5"", + ""@xmlns"": """" + }, + { + ""@Style"": ""{StaticResource trimFormGrid_TB}"", + ""@Text"": ""{Binding IsEnclosed, Converter={StaticResource trimPropertyConverter}}"", + ""@Name"": ""RecordIsEnclosed"", + ""@Grid.Column"": ""1"", + ""@Grid.Row"": ""6"", + ""@xmlns"": """" + }, + { + ""@Style"": ""{StaticResource trimFormGrid_TB}"", + ""@Text"": ""{Binding Assignee, Converter={StaticResource trimPropertyConverter}}"", + ""@Name"": ""RecordAssignee"", + ""@Grid.Column"": ""1"", + ""@Grid.Row"": ""7"", + ""@xmlns"": """" + } + ], + ""toolkit:DatePicker"": [ + { + ""@Style"": ""{StaticResource trimFormGrid_DP}"", + ""@Value"": ""{Binding DateCreated, Converter={StaticResource trimPropertyConverter}}"", + ""@Name"": ""RecordDateCreated"", + ""@Grid.Column"": ""1"", + ""@Grid.Row"": ""2"" + }, + { + ""@Style"": ""{StaticResource trimFormGrid_DP}"", + ""@Value"": ""{Binding DateDue, Converter={StaticResource trimPropertyConverter}}"", + ""@Name"": ""RecordDateDue"", + ""@Grid.Column"": ""1"", + ""@Grid.Row"": ""3"" + } + ], + ""TextBlock"": [ + { + ""@Grid.Column"": ""0"", + ""@Text"": ""Title (Free Text Part)"", + ""@Style"": ""{StaticResource trimFormGrid_LBL}"", + ""@Grid.Row"": ""0"", + ""@xmlns"": """" + }, + { + ""@Grid.Column"": ""0"", + ""@Text"": ""External ID"", + ""@Style"": ""{StaticResource trimFormGrid_LBL}"", + ""@Grid.Row"": ""1"", + ""@xmlns"": """" + }, + { + ""@Grid.Column"": ""0"", + ""@Text"": ""Date Created"", + ""@Style"": ""{StaticResource trimFormGrid_LBL}"", + ""@Grid.Row"": ""2"", + ""@xmlns"": """" + }, + { + ""@Grid.Column"": ""0"", + ""@Text"": ""Date Due"", + ""@Style"": ""{StaticResource trimFormGrid_LBL}"", + ""@Grid.Row"": ""3"", + ""@xmlns"": """" + }, + { + ""@Grid.Column"": ""0"", + ""@Text"": ""Author"", + ""@Style"": ""{StaticResource trimFormGrid_LBL}"", + ""@Grid.Row"": ""4"", + ""@xmlns"": """" + }, + { + ""@Grid.Column"": ""0"", + ""@Text"": ""Container"", + ""@Style"": ""{StaticResource trimFormGrid_LBL}"", + ""@Grid.Row"": ""5"", + ""@xmlns"": """" + }, + { + ""@Grid.Column"": ""0"", + ""@Text"": ""Enclosed?"", + ""@Style"": ""{StaticResource trimFormGrid_LBL}"", + ""@Grid.Row"": ""6"", + ""@xmlns"": """" + }, + { + ""@Grid.Column"": ""0"", + ""@Text"": ""Assignee"", + ""@Style"": ""{StaticResource trimFormGrid_LBL}"", + ""@Grid.Row"": ""7"", + ""@xmlns"": """" + } + ] + } +}"; + + Assert.AreEqual(expectedJson, json); + + XmlNode node = JsonConvert.DeserializeXmlNode(json); + + StringWriter sw = new StringWriter(); + XmlWriter writer = XmlWriter.Create(sw, new XmlWriterSettings + { + Indent = true, + OmitXmlDeclaration = true + }); + node.WriteTo(writer); + writer.Flush(); + + string xaml2 = sw.ToString(); + + string expectedXaml = @" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +"; + + Assert.AreEqual(expectedXaml, xaml2); + } } } #endif \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/JsonTextReaderTest.cs b/Src/Newtonsoft.Json.Tests/JsonTextReaderTest.cs index 446512c6..a1cb8572 100644 --- a/Src/Newtonsoft.Json.Tests/JsonTextReaderTest.cs +++ b/Src/Newtonsoft.Json.Tests/JsonTextReaderTest.cs @@ -1923,5 +1923,15 @@ bye", reader.Value); reader.Read(); Assert.AreEqual(JsonToken.EndArray, reader.TokenType); } + + [Test] + [ExpectedException(typeof(JsonReaderException), ExpectedMessage = "Additional text encountered after finished reading JSON content: }. Line 1, position 2.")] + public void UnexpectedEndTokenWhenParsingOddEndToken() + { + JsonReader reader = new JsonTextReader(new StringReader(@"{}}")); + Assert.IsTrue(reader.Read()); + Assert.IsTrue(reader.Read()); + reader.Read(); + } } } \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.Net20.csproj b/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.Net20.csproj index 135fa42e..f9c40b42 100644 --- a/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.Net20.csproj +++ b/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.Net20.csproj @@ -84,6 +84,7 @@ + diff --git a/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.Net35.csproj b/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.Net35.csproj index b1729d79..af231928 100644 --- a/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.Net35.csproj +++ b/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.Net35.csproj @@ -114,6 +114,7 @@ + diff --git a/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.Silverlight.csproj b/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.Silverlight.csproj index 25d36f25..6a9ae0f8 100644 --- a/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.Silverlight.csproj +++ b/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.Silverlight.csproj @@ -110,6 +110,7 @@ + diff --git a/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.WindowsPhone.csproj b/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.WindowsPhone.csproj index 78fe5a6c..e019d0d0 100644 --- a/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.WindowsPhone.csproj +++ b/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.WindowsPhone.csproj @@ -74,6 +74,7 @@ + diff --git a/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.csproj b/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.csproj index 2a87afd6..925083a8 100644 --- a/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.csproj +++ b/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.csproj @@ -115,6 +115,7 @@ + True True diff --git a/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs b/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs index 032490a9..d1e339ee 100644 --- a/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs +++ b/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs @@ -24,26 +24,32 @@ #endregion using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +using System.Security; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. -#if SILVERLIGHT -[assembly: AssemblyTitle("Newtonsoft Json.NET Tests Silverlight")] +#if WINDOWS_PHONE +[assembly: AssemblyTitle("Json.NET Tests Windows Phone")] +#elif SILVERLIGHT +[assembly: AssemblyTitle("Json.NET Tests Silverlight")] #elif PocketPC -[assembly: AssemblyTitle("Newtonsoft Json.NET Tests Compact")] +[assembly: AssemblyTitle("Json.NET Tests Compact")] +#elif NET20 +[assembly: AssemblyTitle("Json.NET Tests .NET 2.0")] +#elif NET35 +[assembly: AssemblyTitle("Json.NET Tests .NET 3.5")] #else -[assembly: AssemblyTitle("Newtonsoft Json.NET Tests")] +[assembly: AssemblyTitle("Json.NET")] #endif [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Newtonsoft")] -[assembly: AssemblyProduct("Newtonsoft Json.NET Tests")] -[assembly: AssemblyCopyright("Copyright © Newtonsoft 2008")] +[assembly: AssemblyProduct("Json.NET Tests")] +[assembly: AssemblyCopyright("Copyright © James Newton-King 2008")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -64,7 +70,7 @@ using System.Runtime.InteropServices; // // You can specify all the values or you can default the Revision and Build Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("4.0.7.0")] +[assembly: AssemblyVersion("4.0.8.0")] #if !PocketPC -[assembly: AssemblyFileVersion("4.0.7.14610")] +[assembly: AssemblyFileVersion("4.0.8.14611")] #endif diff --git a/Src/Newtonsoft.Json/Converters/VersionConverter.cs b/Src/Newtonsoft.Json/Converters/VersionConverter.cs new file mode 100644 index 00000000..67a9b66d --- /dev/null +++ b/Src/Newtonsoft.Json/Converters/VersionConverter.cs @@ -0,0 +1,109 @@ +#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.Linq; +using System.Text; +using System.Globalization; +using Newtonsoft.Json.Utilities; + +namespace Newtonsoft.Json.Converters +{ + /// + /// Converts a to and from a string (e.g. "1.2.3.4"). + /// + public class VersionConverter : JsonConverter + { + /// + /// Writes the JSON representation of the object. + /// + /// The to write to. + /// The value. + /// The calling serializer. + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + { + if (value == null) + { + writer.WriteNull(); + } + else if (value is Version) + { + writer.WriteValue(value.ToString()); + } + else + { + throw new Exception("Expected Version object value"); + } + } + + /// + /// Reads the JSON representation of the object. + /// + /// The to read from. + /// Type of the object. + /// The existing property value of the JSON that is being converted. + /// The calling serializer. + /// The object value. + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + { + if (reader.TokenType == JsonToken.Null) + { + return null; + } + else + { + if (reader.TokenType == JsonToken.String) + { + try + { + Version v = new Version((string) reader.Value); + return v; + } + catch (Exception ex) + { + throw new Exception("Error parsing version string: {0}".FormatWith(CultureInfo.InvariantCulture, reader.Value), ex); + } + } + else + { + throw new Exception("Unexpected token or value when parsing version. Token: {0}, Value: {1}".FormatWith(CultureInfo.InvariantCulture, reader.TokenType, reader.Value)); + } + } + } + + /// + /// Determines whether this instance can convert the specified object type. + /// + /// Type of the object. + /// + /// true if this instance can convert the specified object type; otherwise, false. + /// + public override bool CanConvert(Type objectType) + { + return objectType == typeof (Version); + } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json/Converters/XmlNodeConverter.cs b/Src/Newtonsoft.Json/Converters/XmlNodeConverter.cs index cd6a9e22..e3a82960 100644 --- a/Src/Newtonsoft.Json/Converters/XmlNodeConverter.cs +++ b/Src/Newtonsoft.Json/Converters/XmlNodeConverter.cs @@ -1426,9 +1426,11 @@ namespace Newtonsoft.Json.Converters private IXmlElement CreateElement(string elementName, IXmlDocument document, string elementPrefix, XmlNamespaceManager manager) { - return (!string.IsNullOrEmpty(elementPrefix)) - ? document.CreateElement(elementName, manager.LookupNamespace(elementPrefix)) - : document.CreateElement(elementName); + string ns = string.IsNullOrEmpty(elementPrefix) ? manager.DefaultNamespace : manager.LookupNamespace(elementPrefix); + + IXmlElement element = (!string.IsNullOrEmpty(ns)) ? document.CreateElement(elementName, ns) : document.CreateElement(elementName); + + return element; } private void DeserializeNode(JsonReader reader, IXmlDocument document, XmlNamespaceManager manager, IXmlNode currentNode) diff --git a/Src/Newtonsoft.Json/Newtonsoft.Json.Net20.csproj b/Src/Newtonsoft.Json/Newtonsoft.Json.Net20.csproj index 6b4275f3..ca9b1fa8 100644 --- a/Src/Newtonsoft.Json/Newtonsoft.Json.Net20.csproj +++ b/Src/Newtonsoft.Json/Newtonsoft.Json.Net20.csproj @@ -91,6 +91,7 @@ + diff --git a/Src/Newtonsoft.Json/Newtonsoft.Json.Net35.csproj b/Src/Newtonsoft.Json/Newtonsoft.Json.Net35.csproj index 4f79b12f..54c0188b 100644 --- a/Src/Newtonsoft.Json/Newtonsoft.Json.Net35.csproj +++ b/Src/Newtonsoft.Json/Newtonsoft.Json.Net35.csproj @@ -103,6 +103,7 @@ + diff --git a/Src/Newtonsoft.Json/Newtonsoft.Json.Silverlight.csproj b/Src/Newtonsoft.Json/Newtonsoft.Json.Silverlight.csproj index 8dca56ec..1cd58687 100644 --- a/Src/Newtonsoft.Json/Newtonsoft.Json.Silverlight.csproj +++ b/Src/Newtonsoft.Json/Newtonsoft.Json.Silverlight.csproj @@ -102,6 +102,7 @@ + diff --git a/Src/Newtonsoft.Json/Newtonsoft.Json.WindowsPhone.csproj b/Src/Newtonsoft.Json/Newtonsoft.Json.WindowsPhone.csproj index 93b4b1c1..6825dd52 100644 --- a/Src/Newtonsoft.Json/Newtonsoft.Json.WindowsPhone.csproj +++ b/Src/Newtonsoft.Json/Newtonsoft.Json.WindowsPhone.csproj @@ -75,6 +75,7 @@ + diff --git a/Src/Newtonsoft.Json/Newtonsoft.Json.csproj b/Src/Newtonsoft.Json/Newtonsoft.Json.csproj index 980a105a..529ca24e 100644 --- a/Src/Newtonsoft.Json/Newtonsoft.Json.csproj +++ b/Src/Newtonsoft.Json/Newtonsoft.Json.csproj @@ -102,6 +102,7 @@ + diff --git a/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs b/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs index 877c5cc3..86c838f0 100644 --- a/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs +++ b/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs @@ -33,19 +33,19 @@ using System.Security; // set of attributes. Change these attribute values to modify the information // associated with an assembly. #if WINDOWS_PHONE -[assembly: AssemblyTitle("Newtonsoft Json.NET Windows Phone")] +[assembly: AssemblyTitle("Json.NET Windows Phone")] #elif SILVERLIGHT -[assembly: AssemblyTitle("Newtonsoft Json.NET Silverlight")] +[assembly: AssemblyTitle("Json.NET Silverlight")] #elif PocketPC -[assembly: AssemblyTitle("Newtonsoft Json.NET Compact")] +[assembly: AssemblyTitle("Json.NET Compact")] #elif NET20 -[assembly: AssemblyTitle("Newtonsoft Json.NET .NET 2.0")] +[assembly: AssemblyTitle("Json.NET .NET 2.0")] [assembly: AllowPartiallyTrustedCallers] #elif NET35 -[assembly: AssemblyTitle("Newtonsoft Json.NET .NET 3.5")] +[assembly: AssemblyTitle("Json.NET .NET 3.5")] [assembly: AllowPartiallyTrustedCallers] #else -[assembly: AssemblyTitle("Newtonsoft Json.NET")] +[assembly: AssemblyTitle("Json.NET")] [assembly: AllowPartiallyTrustedCallers] #endif @@ -57,11 +57,11 @@ using System.Security; [assembly: InternalsVisibleTo("Newtonsoft.Json.Dynamic, PublicKey=0024000004800000940000000602000000240000525341310004000001000100cbd8d53b9d7de30f1f1278f636ec462cf9c254991291e66ebb157a885638a517887633b898ccbcf0d5c5ff7be85a6abe9e765d0ac7cd33c68dac67e7e64530e8222101109f154ab14a941c490ac155cd1d4fcba0fabb49016b4ef28593b015cab5937da31172f03f67d09edda404b88a60023f062ae71d0b2e4438b74cc11dc9")] -[assembly: AssemblyDescription("")] +[assembly: AssemblyDescription("Json.NET is a popular high-performance JSON framework for .NET")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Newtonsoft")] -[assembly: AssemblyProduct("Newtonsoft Json.NET")] -[assembly: AssemblyCopyright("Copyright © Newtonsoft 2008")] +[assembly: AssemblyProduct("Json.NET")] +[assembly: AssemblyCopyright("Copyright © James Newton-King 2008")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -83,9 +83,9 @@ using System.Security; // // You can specify all the values or you can default the Revision and Build Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("4.0.7.0")] +[assembly: AssemblyVersion("4.0.8.0")] #if !PocketPC -[assembly: AssemblyFileVersion("4.0.7.14610")] +[assembly: AssemblyFileVersion("4.0.8.14611")] #endif [assembly: CLSCompliant(true)]