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

Deeply nested JsonNode throws StackOverflowError for toString() #3447

Closed
deniz-husaj opened this issue Apr 5, 2022 · 3 comments
Closed

Deeply nested JsonNode throws StackOverflowError for toString() #3447

deniz-husaj opened this issue Apr 5, 2022 · 3 comments
Labels
performance Issue related to performance problems or enhancements
Milestone

Comments

@deniz-husaj
Copy link

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
@deniz-husaj deniz-husaj added the to-evaluate Issue that has been received but not yet evaluated label Apr 5, 2022
@cowtowncoder cowtowncoder added 2.14 performance Issue related to performance problems or enhancements and removed to-evaluate Issue that has been received but not yet evaluated labels Apr 5, 2022
@cowtowncoder
Copy link
Member

Makes sense. Note that ObjectNode may also be just programmatically constructed, no need to parse per se.

Would be nice to change this specific serialization iterative (over recursion-based) if practical.

@cowtowncoder
Copy link
Member

Hmmmh. Probably have to special case handling of actual ObjectNode and ArrayNode implementations (but delegate to everyone else). Probably doable, somewhat similar to non-recursive deserialization.

cowtowncoder added a commit that referenced this issue May 3, 2022
cowtowncoder added a commit that referenced this issue May 3, 2022
@cowtowncoder cowtowncoder added this to the 2.14.0 milestone May 4, 2022
@cowtowncoder
Copy link
Member

Implemented, will be in 2.14.0 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Issue related to performance problems or enhancements
Projects
None yet
Development

No branches or pull requests

2 participants