diff --git a/Build/Newtonsoft.Json.nuspec b/Build/Newtonsoft.Json.nuspec index ccc56f67..13268bd0 100644 --- a/Build/Newtonsoft.Json.nuspec +++ b/Build/Newtonsoft.Json.nuspec @@ -2,7 +2,7 @@ Newtonsoft.Json - 4.5.2 + 4.5.3 Json.NET Json.NET is a popular high-performance JSON framework for .NET James Newton-King diff --git a/Build/build.ps1 b/Build/build.ps1 index e5e777e0..9883d8a3 100644 --- a/Build/build.ps1 +++ b/Build/build.ps1 @@ -1,7 +1,7 @@ properties { - $zipFileName = "Json45r1.zip" + $zipFileName = "Json45r3.zip" $majorVersion = "4.5" - $majorWithReleaseVersion = "4.5.2" + $majorWithReleaseVersion = "4.5.3" $version = GetVersion $majorWithReleaseVersion $signAssemblies = $false $signKeyPath = "D:\Development\Releases\newtonsoft.snk" diff --git a/Src/Newtonsoft.Json.Tests/JsonTextReaderTest.cs b/Src/Newtonsoft.Json.Tests/JsonTextReaderTest.cs index 79a99806..529cbf73 100644 --- a/Src/Newtonsoft.Json.Tests/JsonTextReaderTest.cs +++ b/Src/Newtonsoft.Json.Tests/JsonTextReaderTest.cs @@ -2282,6 +2282,65 @@ bye", reader.Value); }); } + [Test] + public void MaxDepthDoesNotRecursivelyError() + { + string json = "[[[[]]],[[]]]"; + + JsonTextReader reader = new JsonTextReader(new StringReader(json)) + { + MaxDepth = 1 + }; + + Assert.IsTrue(reader.Read()); + Assert.AreEqual(0, reader.Depth); + + ExceptionAssert.Throws( + "The reader's MaxDepth of 1 has been exceeded. Line 1, position 2.", + () => + { + Assert.IsTrue(reader.Read()); + }); + Assert.AreEqual(1, reader.Depth); + + Assert.IsTrue(reader.Read()); + Assert.AreEqual(2, reader.Depth); + + Assert.IsTrue(reader.Read()); + Assert.AreEqual(3, reader.Depth); + + Assert.IsTrue(reader.Read()); + Assert.AreEqual(3, reader.Depth); + + Assert.IsTrue(reader.Read()); + Assert.AreEqual(2, reader.Depth); + + Assert.IsTrue(reader.Read()); + Assert.AreEqual(1, reader.Depth); + + ExceptionAssert.Throws( + "The reader's MaxDepth of 1 has been exceeded. Line 1, position 9.", + () => + { + Assert.IsTrue(reader.Read()); + }); + Assert.AreEqual(1, reader.Depth); + + Assert.IsTrue(reader.Read()); + Assert.AreEqual(2, reader.Depth); + + Assert.IsTrue(reader.Read()); + Assert.AreEqual(2, reader.Depth); + + Assert.IsTrue(reader.Read()); + Assert.AreEqual(1, reader.Depth); + + Assert.IsTrue(reader.Read()); + Assert.AreEqual(0, reader.Depth); + + Assert.IsFalse(reader.Read()); + } + [Test] public void ReadingFromSlowStream() { diff --git a/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs b/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs index 31d37fe1..c7cf16d0 100644 --- a/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs +++ b/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs @@ -72,5 +72,5 @@ using System.Security; // by using the '*' as shown below: [assembly: AssemblyVersion("4.5.0.0")] #if !PocketPC -[assembly: AssemblyFileVersion("4.5.2.14811")] +[assembly: AssemblyFileVersion("4.5.2.14814")] #endif diff --git a/Src/Newtonsoft.Json.Tests/Schema/JsonSchemaGeneratorTests.cs b/Src/Newtonsoft.Json.Tests/Schema/JsonSchemaGeneratorTests.cs index 93378013..9e9b90fe 100644 --- a/Src/Newtonsoft.Json.Tests/Schema/JsonSchemaGeneratorTests.cs +++ b/Src/Newtonsoft.Json.Tests/Schema/JsonSchemaGeneratorTests.cs @@ -524,6 +524,10 @@ namespace Newtonsoft.Json.Tests.Schema public void GenerateSchemaSerializable() { JsonSchemaGenerator generator = new JsonSchemaGenerator(); + generator.ContractResolver = new DefaultContractResolver + { + IgnoreSerializableAttribute = false + }; generator.UndefinedSchemaIdHandling = UndefinedSchemaIdHandling.UseTypeName; JsonSchema schema = generator.Generate(typeof (Version), true); @@ -559,6 +563,10 @@ namespace Newtonsoft.Json.Tests.Schema JTokenWriter jsonWriter = new JTokenWriter(); JsonSerializer serializer = new JsonSerializer(); + serializer.ContractResolver = new DefaultContractResolver + { + IgnoreSerializableAttribute = false + }; serializer.Serialize(jsonWriter, new Version(1, 2, 3, 4)); List errors = new List(); @@ -573,7 +581,7 @@ namespace Newtonsoft.Json.Tests.Schema ""_Revision"": 4 }", jsonWriter.Token.ToString()); - Version version = jsonWriter.Token.ToObject(); + Version version = jsonWriter.Token.ToObject(serializer); Assert.AreEqual(1, version.Major); Assert.AreEqual(2, version.Minor); Assert.AreEqual(3, version.Build); diff --git a/Src/Newtonsoft.Json.Tests/Serialization/TypeNameHandlingTests.cs b/Src/Newtonsoft.Json.Tests/Serialization/TypeNameHandlingTests.cs index 9b9a6508..fbb09e72 100644 --- a/Src/Newtonsoft.Json.Tests/Serialization/TypeNameHandlingTests.cs +++ b/Src/Newtonsoft.Json.Tests/Serialization/TypeNameHandlingTests.cs @@ -26,8 +26,10 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Globalization; using System.Runtime.Serialization.Formatters; using Newtonsoft.Json.Linq; +using Newtonsoft.Json.Serialization; using Newtonsoft.Json.Tests.TestObjects; #if !NETFX_CORE using NUnit.Framework; @@ -949,6 +951,59 @@ namespace Newtonsoft.Json.Tests.Serialization Assert.AreEqual(e, f, "Objects should be equal after round trip json serialization"); } #endif + +#if !(NET20 || NET35) + [Test] + public void SerializationBinderWithFullName() + { + Message message = new Message + { + Address = "jamesnk@testtown.com", + Body = new Version(1, 2, 3, 4) + }; + + string json = JsonConvert.SerializeObject(message, Formatting.Indented, new JsonSerializerSettings + { + TypeNameHandling = TypeNameHandling.All, + TypeNameAssemblyFormat = FormatterAssemblyStyle.Full, + Binder = new MetroBinder(), + ContractResolver = new DefaultContractResolver + { +#if !(SILVERLIGHT || NETFX_CORE) + IgnoreSerializableAttribute = true +#endif + } + }); + + Assert.AreEqual(@"{ + ""$type"": "":::MESSAGE:::, AssemblyName"", + ""Address"": ""jamesnk@testtown.com"", + ""Body"": { + ""$type"": "":::VERSION:::, AssemblyName"", + ""Major"": 1, + ""Minor"": 2, + ""Build"": 3, + ""Revision"": 4, + ""MajorRevision"": 0, + ""MinorRevision"": 4 + } +}", json); + } + + public class MetroBinder : SerializationBinder + { + public override Type BindToType(string assemblyName, string typeName) + { + return null; + } + + public override void BindToName(Type serializedType, out string assemblyName, out string typeName) + { + assemblyName = "AssemblyName"; + typeName = ":::" + serializedType.Name.ToUpper(CultureInfo.InvariantCulture) + ":::"; + } + } +#endif } public class Message diff --git a/Src/Newtonsoft.Json.Tests/Serialization/WebApiIntegrationTests.cs b/Src/Newtonsoft.Json.Tests/Serialization/WebApiIntegrationTests.cs index 7e0ea8e1..bdbc1425 100644 --- a/Src/Newtonsoft.Json.Tests/Serialization/WebApiIntegrationTests.cs +++ b/Src/Newtonsoft.Json.Tests/Serialization/WebApiIntegrationTests.cs @@ -9,6 +9,7 @@ using NUnit.Framework; #if !(SILVERLIGHT || NETFX_CORE || NET20) using System.Runtime.Serialization.Json; #endif +using Newtonsoft.Json.Serialization; namespace Newtonsoft.Json.Tests.Serialization { @@ -39,7 +40,15 @@ namespace Newtonsoft.Json.Tests.Serialization #endif string expected = "{\"publicField\":\"public\",\"internalField\":\"internal\",\"protectedInternalField\":\"protected internal\",\"protectedField\":\"protected\",\"privateField\":\"private\"}"; - string json = JsonConvert.SerializeObject(serializableType); + string json = JsonConvert.SerializeObject(serializableType, new JsonSerializerSettings + { + ContractResolver = new DefaultContractResolver + { +#if !(SILVERLIGHT || NETFX_CORE) + IgnoreSerializableAttribute = false +#endif + } + }); Assert.AreEqual(expected, json); } diff --git a/Src/Newtonsoft.Json/JsonReader.cs b/Src/Newtonsoft.Json/JsonReader.cs index 40dd9d4c..3d193cb3 100644 --- a/Src/Newtonsoft.Json/JsonReader.cs +++ b/Src/Newtonsoft.Json/JsonReader.cs @@ -110,6 +110,7 @@ namespace Newtonsoft.Json private CultureInfo _culture; private DateTimeZoneHandling _dateTimeZoneHandling; private int? _maxDepth; + private bool _hasExceededMaxDepth; /// /// Gets the current reader state. @@ -258,8 +259,11 @@ namespace Newtonsoft.Json _currentPosition = state; // this is a little hacky because Depth increases when first property/value is written but only testing here is faster/simpler - if (_maxDepth != null && Depth + 1 > _maxDepth) + if (_maxDepth != null && Depth + 1 > _maxDepth && !_hasExceededMaxDepth) + { + _hasExceededMaxDepth = true; throw CreateReaderException(this, "The reader's MaxDepth of {0} has been exceeded.".FormatWith(CultureInfo.InvariantCulture, _maxDepth)); + } } } @@ -278,6 +282,9 @@ namespace Newtonsoft.Json _currentPosition = new JsonPosition(); } + if (_maxDepth != null && Depth <= _maxDepth) + _hasExceededMaxDepth = false; + return oldPosition.Type; } diff --git a/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs b/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs index 61f5e43e..74e793c5 100644 --- a/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs +++ b/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs @@ -88,7 +88,7 @@ using System.Security; // by using the '*' as shown below: [assembly: AssemblyVersion("4.5.0.0")] #if !PocketPC -[assembly: AssemblyFileVersion("4.5.2.14811")] +[assembly: AssemblyFileVersion("4.5.2.14814")] #endif [assembly: CLSCompliant(true)] diff --git a/Src/Newtonsoft.Json/Serialization/DefaultContractResolver.cs b/Src/Newtonsoft.Json/Serialization/DefaultContractResolver.cs index 2e3396ff..7fee6a71 100644 --- a/Src/Newtonsoft.Json/Serialization/DefaultContractResolver.cs +++ b/Src/Newtonsoft.Json/Serialization/DefaultContractResolver.cs @@ -191,6 +191,10 @@ namespace Newtonsoft.Json.Serialization #if !NETFX_CORE DefaultMembersSearchFlags = BindingFlags.Public | BindingFlags.Instance; #endif +#if !(SILVERLIGHT || NETFX_CORE) + IgnoreSerializableAttribute = true; +#endif + _sharedCache = shareCache; } diff --git a/Src/Newtonsoft.Json/Utilities/ReflectionUtils.cs b/Src/Newtonsoft.Json/Utilities/ReflectionUtils.cs index c676cc94..1c6984e7 100644 --- a/Src/Newtonsoft.Json/Utilities/ReflectionUtils.cs +++ b/Src/Newtonsoft.Json/Utilities/ReflectionUtils.cs @@ -186,7 +186,7 @@ namespace Newtonsoft.Json.Utilities case FormatterAssemblyStyle.Simple: return RemoveAssemblyDetails(fullyQualifiedTypeName); case FormatterAssemblyStyle.Full: - return t.AssemblyQualifiedName; + return fullyQualifiedTypeName; default: throw new ArgumentOutOfRangeException(); }