Skip to content

Fix metadata parsing for JSON object strings - #122

Merged
cb-alish merged 1 commit into
chargebee:v4from
cb-yashmohan:fix/string-metadata-parsing
Oct 19, 2026
Merged

cb-alish merged 1 commit into
chargebee:v4from
cb-yashmohan:fix/string-metadata-parsing

Conversation

@cb-yashmohan

@cb-yashmohan cb-yashmohan commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Description

Preserve metadata when an API response contains a string that holds a JSON object. In v4.17.0, JsonUtil.getJsonObject() rejects this form, and generated model parsers return an empty metadata map.

Decode string values once in the shared object reader. Keep support for normal JSON objects and preserve existing behavior for missing, null, malformed, and non-object values. This covers GrantBlock, Item, and ItemPrice without changes to generated models or public signatures.

Related Issues

No linked GitHub issue.

Additional Information

  • Added regression coverage through the real Allocate client and a local HTTP server, for both synchronous and asynchronous calls.
  • Covered object and string forms, nested values, Unicode, escapes, null array elements, and JSON-looking strings that must remain strings.
  • The original v4.17.0 code failed five regression cases. The fixed code passes all 126 focused tests.
  • A clean local build and the final broader run passed 677 tests. Five existing tests that attempt non-local connections or DNS lookups were excluded from local verification only; this PR does not change CI test selection.
  • One existing localhost form-body test failed during the first broader run. It passed its focused retry and the final broader run without edits.

Updated JsonUtil.getJsonObject to parse string-encoded JSON objects while preserving existing handling of invalid and non-object values. Added unit and metadata parser tests for GrantBlock, Item, and ItemPrice, including synchronous and asynchronous Allocate requests.

Decode JSON object strings in the shared response reader so metadata is not
replaced by an empty map. Preserve normal object and invalid-value behavior.
Add regression coverage for Allocate, Item, and ItemPrice metadata.
@snyk-io

snyk-io Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

✅ Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues
✅ Licenses 0 0 0 0 0 issues
✅ Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@coderabbitai

coderabbitai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Enterprise
  • Run ID: 38b857b2-25e0-4f78-a8c8-17beb09fd710
📥 Commits

Reviewing files that changed from the base of the PR and between 7d728f7 and 399811b.

📒 Files selected for processing: 3
  • src/main/java/com/chargebee/v4/internal/JsonUtil.java
  • src/test/java/com/chargebee/v4/internal/JsonUtilTest.java
  • src/test/java/com/chargebee/v4/internal/MetadataParserTest.java

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.

Walkthrough

JsonUtil.getJsonObject now parses string-valued JSON and returns the result only when it is an object. Tests cover valid and invalid values and metadata parsing in allocation, Item, and ItemPrice.

Changes

Metadata parsing

Layer / File(s) Summary
String-valued JSON object parsing and metadata validation
src/main/java/com/chargebee/v4/internal/JsonUtil.java, src/test/java/com/chargebee/v4/internal/JsonUtilTest.java, src/test/java/com/chargebee/v4/internal/MetadataParserTest.java
getJsonObject parses string-valued JSON and returns null when parsing fails or the value is not an object. Tests cover valid and invalid strings and metadata handling in allocation requests and responses, Item, and ItemPrice.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: cb-karthikp

Merge Risk: ⚪ Minimal · up to 39981

No actionable merge-blocking issue is identified; this change is ready for normal merge checks.

Pre-merge checks: Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 18.18% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
  • Fix all pre-merge checks with AI
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@cb-alish
cb-alish merged commit 129abb7 into chargebee:v4 Oct 19, 2026
6 checks passed
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