Skip to content

Commit b358792

Browse files
committed
Add failing test for #2816
1 parent 0e1cd09 commit b358792

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.fasterxml.jackson.failing;
2+
3+
import java.util.List;
4+
import java.util.Map;
5+
6+
import com.fasterxml.jackson.databind.*;
7+
8+
// [databind#2816]
9+
public class DeepNestingWithUntyped2816Test extends BaseMapTest
10+
{
11+
// 2000 passes, 3000 fails
12+
private final static int TOO_DEEP_NESTING = 4000;
13+
14+
private final ObjectMapper MAPPER = newJsonMapper();
15+
16+
public void testWithArray() throws Exception
17+
{
18+
final String doc = _nestedDoc(TOO_DEEP_NESTING, "[ ", "] ");
19+
Object ob = MAPPER.readValue(doc, Object.class);
20+
assertTrue(ob instanceof List<?>);
21+
}
22+
23+
public void testWithObject() throws Exception
24+
{
25+
final String doc = "{"+_nestedDoc(TOO_DEEP_NESTING, "\"x\":{", "} ") + "}";
26+
Object ob = MAPPER.readValue(doc, Object.class);
27+
assertTrue(ob instanceof Map<?,?>);
28+
}
29+
30+
private String _nestedDoc(int nesting, String open, String close) {
31+
StringBuilder sb = new StringBuilder(nesting * (open.length() + close.length()));
32+
for (int i = 0; i < nesting; ++i) {
33+
sb.append(open);
34+
if ((i & 31) == 0) {
35+
sb.append("\n");
36+
}
37+
}
38+
for (int i = 0; i < nesting; ++i) {
39+
sb.append(close);
40+
if ((i & 31) == 0) {
41+
sb.append("\n");
42+
}
43+
}
44+
return sb.toString();
45+
}
46+
}

0 commit comments

Comments
 (0)