diff --git a/JsonSubTypes.Tests.Net35/App.config b/JsonSubTypes.Tests.Net35/App.config index c5871a5..fe82973 100644 --- a/JsonSubTypes.Tests.Net35/App.config +++ b/JsonSubTypes.Tests.Net35/App.config @@ -4,7 +4,7 @@ - + diff --git a/JsonSubTypes.Tests.Net35/JsonSubTypes.Tests.Net35.csproj b/JsonSubTypes.Tests.Net35/JsonSubTypes.Tests.Net35.csproj index 91ae8e8..ecab848 100644 --- a/JsonSubTypes.Tests.Net35/JsonSubTypes.Tests.Net35.csproj +++ b/JsonSubTypes.Tests.Net35/JsonSubTypes.Tests.Net35.csproj @@ -15,7 +15,7 @@ TRACE;NET35 - + diff --git a/JsonSubTypes.Tests/App.config b/JsonSubTypes.Tests/App.config index c5871a5..fe82973 100644 --- a/JsonSubTypes.Tests/App.config +++ b/JsonSubTypes.Tests/App.config @@ -4,7 +4,7 @@ - + diff --git a/JsonSubTypes.Tests/DeeplyNestedDeserializationTests.cs b/JsonSubTypes.Tests/DeeplyNestedDeserializationTests.cs new file mode 100644 index 0000000..9eadc02 --- /dev/null +++ b/JsonSubTypes.Tests/DeeplyNestedDeserializationTests.cs @@ -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(json, new JsonSerializerSettings { MaxDepth = 65 }); + Assert.That(obj, Is.Not.Null); + } + } +} diff --git a/JsonSubTypes.Tests/JsonSubTypes.Tests.csproj b/JsonSubTypes.Tests/JsonSubTypes.Tests.csproj index 702bfad..06cf648 100644 --- a/JsonSubTypes.Tests/JsonSubTypes.Tests.csproj +++ b/JsonSubTypes.Tests/JsonSubTypes.Tests.csproj @@ -16,7 +16,7 @@ - + diff --git a/JsonSubTypes/JsonSubtypes.cs b/JsonSubTypes/JsonSubtypes.cs index 8f729c7..3d7f04b 100644 --- a/JsonSubTypes/JsonSubtypes.cs +++ b/JsonSubTypes/JsonSubtypes.cs @@ -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; } diff --git a/JsonSubTypes/packages.config b/JsonSubTypes/packages.config index 851e05d..3fe2661 100644 --- a/JsonSubTypes/packages.config +++ b/JsonSubTypes/packages.config @@ -1,4 +1,4 @@  - +