Skip to content

chore: sync upstream PR #8087 - Use JSONTokener for application/json reponse parsing#27

Open
riderx wants to merge 7 commits intoplusfrom
sync/upstream-pr-8087
Open

chore: sync upstream PR #8087 - Use JSONTokener for application/json reponse parsing#27
riderx wants to merge 7 commits intoplusfrom
sync/upstream-pr-8087

Conversation

@riderx
Copy link
Member

@riderx riderx commented Nov 28, 2025

Upstream PR Sync

This PR syncs changes from an external contributor's PR on the official Capacitor repository.

Original PR

  • PR: #8087
  • Title: Use JSONTokener for application/json reponse parsing
  • Author: @Crylion

Automation

  • CI will run automatically
  • Claude Code will review for security/breaking changes
  • If approved, this PR will be auto-merged

Synced from upstream by Capacitor+ Bot

Summary by CodeRabbit

Bug Fixes

  • Improved JSON parsing reliability with enhanced fallback mechanisms to better support various JSON formats and reduce parsing errors.
  • Better error handling for edge cases and unexpected data structures in HTTP request processing.
  • Enhanced overall stability and resilience of JSON data handling.
  • More consistent parsing behavior across different types of JSON input.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Nov 28, 2025

📝 Walkthrough

Walkthrough

Modified the parseJSON method in HttpRequestHandler to implement a multi-step fallback parsing strategy. Removed the explicit throws JSONException declaration and added sequential try-catch blocks that attempt parsing as JSObject, JSArray, and literal values before returning the input string unchanged.

Changes

Cohort / File(s) Summary
JSON Parsing Enhancement
android/capacitor/src/main/java/com/getcapacitor/plugin/util/HttpRequestHandler.java
Updated parseJSON(String input) method signature to remove throws JSONException clause. Replaced direct parsing with fallback strategy: attempts JSObject → JSArray → JSONTokener literal parsing → returns input string. Modified imports (removed JSONObject, added JSONTokener). Updated Javadoc to document new return type possibilities.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐰 A parsing path with hops so wise,
First objects, then arrays we scrutinize,
If those fail, literals catch our eye,
Or strings unscathed just hop on by!
No exceptions thrown, just graceful returns,
The JSON handling smoothly turns! 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately reflects the main change: syncing upstream PR #8087 which implements JSONTokener for JSON response parsing in the HttpRequestHandler.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings


📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bbc12ec and c91a93a.

📒 Files selected for processing (1)
  • android/capacitor/src/main/java/com/getcapacitor/plugin/util/HttpRequestHandler.java
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: test-ios (/Applications/Xcode_26.0.app)
  • GitHub Check: test-cli
  • GitHub Check: test-core
  • GitHub Check: test-android
🔇 Additional comments (2)
android/capacitor/src/main/java/com/getcapacitor/plugin/util/HttpRequestHandler.java (2)

29-29: LGTM!

The JSONTokener import is appropriate for parsing JSON literals.


305-325: Solid improvement for JSON literal parsing.

The multi-step fallback strategy correctly handles JSON primitives including numbers, booleans, null, and quoted strings via JSONTokener.nextValue().

Note on API change: The removal of throws JSONException is a breaking change for external callers. While no external consumers exist in this repository, any code outside depending on exception-based error detection will now receive the raw input string instead. Internal callers in this file are compatible with the new behavior since they don't catch the exception and directly return the result.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@riderx riderx force-pushed the sync/upstream-pr-8087 branch from 99b568c to 82147d3 Compare November 28, 2025 15:02
@riderx riderx force-pushed the sync/upstream-pr-8087 branch from 82147d3 to c91a93a Compare January 14, 2026 06:04
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.

2 participants