Skip to content

Commit 1673e0f

Browse files
committed
Fixed stack overflow when mapping recursive collections
1 parent e52f8a1 commit 1673e0f

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

Diff for: src/Nest/Resolvers/Writers/TypeMappingWriter.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ internal void WriteProperties(JsonWriter jsonWriter)
155155
if (type == "object" || type == "nested")
156156
{
157157

158-
var deepType = p.PropertyType;
158+
var deepType = GetUnderlyingType(p.PropertyType);
159159
var deepTypeName = this.Infer.TypeName(deepType);
160160
var seenTypes = new ConcurrentDictionary<Type, int>(this.SeenTypes);
161161
seenTypes.AddOrUpdate(deepType, 0, (t, i) => ++i);

Diff for: src/Tests/Nest.Tests.Unit/Core/AttributeBasedMap/DeepObjectMappingTests.cs

+12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using NUnit.Framework;
2+
using System.Collections.Generic;
23

34
namespace Nest.Tests.Unit.Core.AttributeBasedMap
45
{
@@ -29,6 +30,12 @@ private class NestedRecursiveMapChild
2930
public string Name { get; set; }
3031
public NestedRecursiveMapParent Parent { get; set; }
3132
}
33+
private class RecursiveMapCollection
34+
{
35+
public string Name { get; set; }
36+
public IEnumerable<RecursiveMapCollection> Items { get; set; }
37+
}
38+
3239
[Test]
3340
public void TestDeepObjectWriter()
3441
{
@@ -41,5 +48,10 @@ public void TestDeepObjectResursiveWriter()
4148
//make sure we dont stackoverflow because of a never ending recursion
4249
Assert.DoesNotThrow(() => this.CreateMapFor<NestedRecursiveMapParent>() );
4350
}
51+
[Test]
52+
public void TestRecursiveCollectionWriter()
53+
{
54+
Assert.DoesNotThrow(() => this.CreateMapFor<RecursiveMapCollection>());
55+
}
4456
}
4557
}

0 commit comments

Comments
 (0)