Skip to content

Use JSONTokener for application/json reponse parsing #8087

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

Crylion
Copy link
Contributor

@Crylion Crylion commented Jul 28, 2025

I'm changing the way the core HTTP plugin parses JSON responses, because I encountered a problem with a specific response from an API:
The request in question returns an application/json response that is just a 64bit number literal.

Screenshot 2025-07-28 at 12 21 10

Unfortunately, the way the parser in HttpRequestHandler.java works, is that it tries to parse number literals without a decimal point as a 32bit Integer, which fails for a number this size.
Now, the easiest fix would have been to just change the type to Long here, but that seemed a bit short sighted, because there seem to have been a lot of changes to this parser for specific scenarios like this, so a new approach seemed the better choice. As you can see in my commits, I first tried to just copy&paste the parser logic that JSObject/JSArray use internally to literals, but that seemed silly to me, because at that point, why not just USE the internal parser instead of trying to recreate most of what it does.

So my change gets rid of all the specific logic for all the different types of literals, and just uses the parser of the JSONTokener instead. In it's readLiteral method, the Tokener basically does the exact same thing the long if/else statement here did before, but better.
Now I just try to parse the input as first an object, then an array, and if that does not work, I just use the Tokener directly to let it parse the input as a literal.

I tested it with all of the literals that were processed here before and the result for all of them is the same as before, but now Long values work too, and we hopefully don't have to add more special cases to this method anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant