Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy MaxDepth when creating internal JObjectReader #137

Merged
merged 3 commits into from
Sep 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion JsonSubTypes.Tests.Net35/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
<bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
Expand Down
2 changes: 1 addition & 1 deletion JsonSubTypes.Tests.Net35/JsonSubTypes.Tests.Net35.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<DefineConstants>TRACE;NET35</DefineConstants>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="NUnit" Version="3.13.2" />
<PackageReference Include="TaskParallelLibrary" Version="1.0.2856.0" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion JsonSubTypes.Tests/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
<bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
Expand Down
41 changes: 41 additions & 0 deletions JsonSubTypes.Tests/DeeplyNestedDeserializationTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using Newtonsoft.Json;
using NUnit.Framework;

namespace JsonSubTypes.Tests
{
[TestFixture]
public class DeeplyNestedDeserializationTests
{
[JsonConverter(typeof(JsonSubtypes), nameof(SubTypeClass.Discriminator))]
[JsonSubtypes.KnownSubType(typeof(SubTypeClass), "SubTypeClass")]
public abstract class MainClass
{
}

public class SubTypeClass : MainClass
{
public string Discriminator => "SubTypeClass";

public MainClass Child { get; set; }
}

[Test]
public void DeserializingDeeplyNestedJsonWithHighMaxDepthParsesCorrectly()
{
var root = new SubTypeClass();

var current = root;
for (var i = 0; i < 64; i++)
{
var child = new SubTypeClass();
current.Child = child;
current = child;
}

var json = JsonConvert.SerializeObject(root);

var obj = JsonConvert.DeserializeObject<MainClass>(json, new JsonSerializerSettings { MaxDepth = 65 });
Assert.That(obj, Is.Not.Null);
}
}
}
2 changes: 1 addition & 1 deletion JsonSubTypes.Tests/JsonSubTypes.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</PropertyGroup>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="NUnit" Version="3.13.2" />
</ItemGroup>
<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions JsonSubTypes/JsonSubtypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ private static JsonReader CreateAnotherReader(JToken jToken, JsonReader reader)
jObjectReader.FloatParseHandling = reader.FloatParseHandling;
jObjectReader.DateFormatString = reader.DateFormatString;
jObjectReader.DateParseHandling = reader.DateParseHandling;
jObjectReader.MaxDepth = reader.MaxDepth;
return jObjectReader;
}

Expand Down
2 changes: 1 addition & 1 deletion JsonSubTypes/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="12.0.3" targetFramework="net47" allowedVersions="[10.0.0, 13.0.0)" />
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net47" allowedVersions="[10.0.0, 14.0.0)" />
</packages>