-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Add nesting limit for JsonReader
#2588
Add nesting limit for JsonReader
#2588
Conversation
For now don't expose this as additional GsonBuilder method assuming that the default nesting limit is high enough for most users. Otherwise users can first obtain a JsonReader from `Gson.newJsonReader` and then set a custom nesting limit.
See comment in JsonTreeReaderTest for the rationale
# Conflicts: # gson/src/main/java/com/google/gson/stream/JsonReader.java # gson/src/test/java/com/google/gson/internal/bind/JsonTreeReaderTest.java
@eamonnmcmanus regarding #2632 (reply in thread): Is there some general problem with this concept of a nesting limit or should I change something? |
Last time I looked, this triggered a test failure in a Google-internal test. I think what I might do is patch Google's internal copy of the Gson source code to increase the threshold so that test passes. I think the limit of 255 is reasonable for the public version. I'm looking into this now. |
Purpose
Add nesting limit for
JsonReader
Description
For now don't expose this as additional GsonBuilder method assuming that the default nesting limit is high enough for most users. Otherwise users can first obtain a JsonReader from
Gson.newJsonReader
and then set a custom nesting limit.The reasons why this pull request makes the nesting limit configurable at all are
JsonReader
can be used directly in a way which does not involve recursion, so for these advanced use cases there might be no limit needed.It appears there are rare cases where users need to handle more deeply nested JSON data; here are examples from other programming languages: Allow to increase maximum JSON nesting depth valyala/fastjson#65, Add configurable recursion limit serde-rs/json#162 (comment)
Checklist
This is automatically checked by
mvn verify
, but can also be checked on its own usingmvn spotless:check
.Style violations can be fixed using
mvn spotless:apply
; this can be done in a separate commit to verify that it did not cause undesired changes.null
@since $next-version$
(
$next-version$
is a special placeholder which is automatically replaced during release)TestCase
)mvn clean verify javadoc:jar
passes without errors