-Incremented version to 4.5.3

-Changed default DefaultContractResolver.IgnoreSerializableAttribute to true
-Fixed MaxDepth on JsonReader recursively throwing error
-Fixed SerializationBinder.BindToName not being called with full assembly names
This commit is contained in:
James Newton-King
2012-04-14 00:58:36 +12:00
parent 11310fdf05
commit adecef2126
11 changed files with 151 additions and 9 deletions
+1 -1
View File
@@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>Newtonsoft.Json</id>
<version>4.5.2</version>
<version>4.5.3</version>
<title>Json.NET</title>
<description>Json.NET is a popular high-performance JSON framework for .NET</description>
<authors>James Newton-King</authors>
+2 -2
View File
@@ -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"
@@ -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<JsonReaderException>(
"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<JsonReaderException>(
"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()
{
@@ -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
@@ -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<string> errors = new List<string>();
@@ -573,7 +581,7 @@ namespace Newtonsoft.Json.Tests.Schema
""_Revision"": 4
}", jsonWriter.Token.ToString());
Version version = jsonWriter.Token.ToObject<Version>();
Version version = jsonWriter.Token.ToObject<Version>(serializer);
Assert.AreEqual(1, version.Major);
Assert.AreEqual(2, version.Minor);
Assert.AreEqual(3, version.Build);
@@ -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
@@ -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);
}
+8 -1
View File
@@ -110,6 +110,7 @@ namespace Newtonsoft.Json
private CultureInfo _culture;
private DateTimeZoneHandling _dateTimeZoneHandling;
private int? _maxDepth;
private bool _hasExceededMaxDepth;
/// <summary>
/// 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;
}
@@ -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)]
@@ -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;
}
@@ -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();
}