-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:
@@ -2,7 +2,7 @@
|
|||||||
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
|
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
|
||||||
<metadata>
|
<metadata>
|
||||||
<id>Newtonsoft.Json</id>
|
<id>Newtonsoft.Json</id>
|
||||||
<version>4.5.2</version>
|
<version>4.5.3</version>
|
||||||
<title>Json.NET</title>
|
<title>Json.NET</title>
|
||||||
<description>Json.NET is a popular high-performance JSON framework for .NET</description>
|
<description>Json.NET is a popular high-performance JSON framework for .NET</description>
|
||||||
<authors>James Newton-King</authors>
|
<authors>James Newton-King</authors>
|
||||||
|
|||||||
+2
-2
@@ -1,7 +1,7 @@
|
|||||||
properties {
|
properties {
|
||||||
$zipFileName = "Json45r1.zip"
|
$zipFileName = "Json45r3.zip"
|
||||||
$majorVersion = "4.5"
|
$majorVersion = "4.5"
|
||||||
$majorWithReleaseVersion = "4.5.2"
|
$majorWithReleaseVersion = "4.5.3"
|
||||||
$version = GetVersion $majorWithReleaseVersion
|
$version = GetVersion $majorWithReleaseVersion
|
||||||
$signAssemblies = $false
|
$signAssemblies = $false
|
||||||
$signKeyPath = "D:\Development\Releases\newtonsoft.snk"
|
$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]
|
[Test]
|
||||||
public void ReadingFromSlowStream()
|
public void ReadingFromSlowStream()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -72,5 +72,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.2.14811")]
|
[assembly: AssemblyFileVersion("4.5.2.14814")]
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -524,6 +524,10 @@ namespace Newtonsoft.Json.Tests.Schema
|
|||||||
public void GenerateSchemaSerializable()
|
public void GenerateSchemaSerializable()
|
||||||
{
|
{
|
||||||
JsonSchemaGenerator generator = new JsonSchemaGenerator();
|
JsonSchemaGenerator generator = new JsonSchemaGenerator();
|
||||||
|
generator.ContractResolver = new DefaultContractResolver
|
||||||
|
{
|
||||||
|
IgnoreSerializableAttribute = false
|
||||||
|
};
|
||||||
generator.UndefinedSchemaIdHandling = UndefinedSchemaIdHandling.UseTypeName;
|
generator.UndefinedSchemaIdHandling = UndefinedSchemaIdHandling.UseTypeName;
|
||||||
|
|
||||||
JsonSchema schema = generator.Generate(typeof (Version), true);
|
JsonSchema schema = generator.Generate(typeof (Version), true);
|
||||||
@@ -559,6 +563,10 @@ namespace Newtonsoft.Json.Tests.Schema
|
|||||||
|
|
||||||
JTokenWriter jsonWriter = new JTokenWriter();
|
JTokenWriter jsonWriter = new JTokenWriter();
|
||||||
JsonSerializer serializer = new JsonSerializer();
|
JsonSerializer serializer = new JsonSerializer();
|
||||||
|
serializer.ContractResolver = new DefaultContractResolver
|
||||||
|
{
|
||||||
|
IgnoreSerializableAttribute = false
|
||||||
|
};
|
||||||
serializer.Serialize(jsonWriter, new Version(1, 2, 3, 4));
|
serializer.Serialize(jsonWriter, new Version(1, 2, 3, 4));
|
||||||
|
|
||||||
List<string> errors = new List<string>();
|
List<string> errors = new List<string>();
|
||||||
@@ -573,7 +581,7 @@ namespace Newtonsoft.Json.Tests.Schema
|
|||||||
""_Revision"": 4
|
""_Revision"": 4
|
||||||
}", jsonWriter.Token.ToString());
|
}", jsonWriter.Token.ToString());
|
||||||
|
|
||||||
Version version = jsonWriter.Token.ToObject<Version>();
|
Version version = jsonWriter.Token.ToObject<Version>(serializer);
|
||||||
Assert.AreEqual(1, version.Major);
|
Assert.AreEqual(1, version.Major);
|
||||||
Assert.AreEqual(2, version.Minor);
|
Assert.AreEqual(2, version.Minor);
|
||||||
Assert.AreEqual(3, version.Build);
|
Assert.AreEqual(3, version.Build);
|
||||||
|
|||||||
@@ -26,8 +26,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
using System.Runtime.Serialization.Formatters;
|
using System.Runtime.Serialization.Formatters;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
using Newtonsoft.Json.Serialization;
|
||||||
using Newtonsoft.Json.Tests.TestObjects;
|
using Newtonsoft.Json.Tests.TestObjects;
|
||||||
#if !NETFX_CORE
|
#if !NETFX_CORE
|
||||||
using NUnit.Framework;
|
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");
|
Assert.AreEqual(e, f, "Objects should be equal after round trip json serialization");
|
||||||
}
|
}
|
||||||
#endif
|
#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
|
public class Message
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ using NUnit.Framework;
|
|||||||
#if !(SILVERLIGHT || NETFX_CORE || NET20)
|
#if !(SILVERLIGHT || NETFX_CORE || NET20)
|
||||||
using System.Runtime.Serialization.Json;
|
using System.Runtime.Serialization.Json;
|
||||||
#endif
|
#endif
|
||||||
|
using Newtonsoft.Json.Serialization;
|
||||||
|
|
||||||
namespace Newtonsoft.Json.Tests.Serialization
|
namespace Newtonsoft.Json.Tests.Serialization
|
||||||
{
|
{
|
||||||
@@ -39,7 +40,15 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
string expected = "{\"publicField\":\"public\",\"internalField\":\"internal\",\"protectedInternalField\":\"protected internal\",\"protectedField\":\"protected\",\"privateField\":\"private\"}";
|
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);
|
Assert.AreEqual(expected, json);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,6 +110,7 @@ namespace Newtonsoft.Json
|
|||||||
private CultureInfo _culture;
|
private CultureInfo _culture;
|
||||||
private DateTimeZoneHandling _dateTimeZoneHandling;
|
private DateTimeZoneHandling _dateTimeZoneHandling;
|
||||||
private int? _maxDepth;
|
private int? _maxDepth;
|
||||||
|
private bool _hasExceededMaxDepth;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the current reader state.
|
/// Gets the current reader state.
|
||||||
@@ -258,8 +259,11 @@ namespace Newtonsoft.Json
|
|||||||
_currentPosition = state;
|
_currentPosition = state;
|
||||||
|
|
||||||
// this is a little hacky because Depth increases when first property/value is written but only testing here is faster/simpler
|
// 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));
|
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();
|
_currentPosition = new JsonPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_maxDepth != null && Depth <= _maxDepth)
|
||||||
|
_hasExceededMaxDepth = false;
|
||||||
|
|
||||||
return oldPosition.Type;
|
return oldPosition.Type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -88,7 +88,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.2.14811")]
|
[assembly: AssemblyFileVersion("4.5.2.14814")]
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
[assembly: CLSCompliant(true)]
|
[assembly: CLSCompliant(true)]
|
||||||
|
|||||||
@@ -191,6 +191,10 @@ namespace Newtonsoft.Json.Serialization
|
|||||||
#if !NETFX_CORE
|
#if !NETFX_CORE
|
||||||
DefaultMembersSearchFlags = BindingFlags.Public | BindingFlags.Instance;
|
DefaultMembersSearchFlags = BindingFlags.Public | BindingFlags.Instance;
|
||||||
#endif
|
#endif
|
||||||
|
#if !(SILVERLIGHT || NETFX_CORE)
|
||||||
|
IgnoreSerializableAttribute = true;
|
||||||
|
#endif
|
||||||
|
|
||||||
_sharedCache = shareCache;
|
_sharedCache = shareCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -186,7 +186,7 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
case FormatterAssemblyStyle.Simple:
|
case FormatterAssemblyStyle.Simple:
|
||||||
return RemoveAssemblyDetails(fullyQualifiedTypeName);
|
return RemoveAssemblyDetails(fullyQualifiedTypeName);
|
||||||
case FormatterAssemblyStyle.Full:
|
case FormatterAssemblyStyle.Full:
|
||||||
return t.AssemblyQualifiedName;
|
return fullyQualifiedTypeName;
|
||||||
default:
|
default:
|
||||||
throw new ArgumentOutOfRangeException();
|
throw new ArgumentOutOfRangeException();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user