Skip to content

Deeply nested JsonNode throws StackOverflowError for toString() #3447

@deniz-husaj

Description

@deniz-husaj

Describe the bug

After parsing a deeply nested JSON input stream to an ObjectMapper the returned JsonNode throws a StackOverflowError for toString().

Method threw 'java.lang.StackOverflowError' exception. Cannot evaluate com.fasterxml.jackson.databind.node.ObjectNode.toString()

Version information
2.13.2.2

To Reproduce

int depth = 50000;
StringBuilder jsonString = new StringBuilder();
jsonString.append("{");

for (int i=0; i < depth; i++) {
  jsonString.append(String.format("\"abc%s\": {", i));
}

for (int i=0; i < depth; i++) {
  jsonString.append("}");
}

jsonString.append("}");

InputStream inputStream = new ByteArrayInputStream(jsonString.toString().getBytes(Charsets.UTF_8));
ObjectMapper objectMapper = new ObjectMapper();
JsonNode jsonNode = objectMapper.readTree(inputStream); 
jsonNode.toString(); // throws StackOverflowError

Metadata

Metadata

Assignees

No one assigned

    Labels

    performanceIssue related to performance problems or enhancements

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions