Skip to content

Regenerate with decimal_string enabled for v2 APIs#2187

Open
jar-stripe wants to merge 2 commits intomasterfrom
jar/enable-decimal-string-v2
Open

Regenerate with decimal_string enabled for v2 APIs#2187
jar-stripe wants to merge 2 commits intomasterfrom
jar/enable-decimal-string-v2

Conversation

@jar-stripe
Copy link
Contributor

@jar-stripe jar-stripe commented Mar 18, 2026

Why?

V2 API decimal fields (e.g. amount on billing meter events) were previously generated as plain String types, even though the same fields in v1 are generated as BigDecimal. A codegen workaround suppressed decimal_string type mapping for all v2 APIs. That workaround has been removed.

What?

  • Regenerated code with decimal_string enabled for v2 APIs
  • V2 decimal fields now use BigDecimal instead of String, matching v1 behavior
  • SDK fix: Added a custom Gson TypeAdapter<BigDecimal> to JsonEncoder.BODY_GSON that serializes BigDecimal as a JSON string (e.g., "75.25" not 75.25). The V2 API expects decimal fields as strings on the wire. V1 doesn't hit this because FormEncoder calls .toString() naturally.

Testing

Integration tested against a live Stripe sandbox (6/6 tests passed):

  1. BigDecimal deserialization from Gson JSON string ✓
  2. BigDecimal null when field absent ✓
  3. BigDecimal high precision (10 decimal places) ✓
  4. Amount consolidation (shared v2.Amount class) ✓
  5. Live V2 Account create with BigDecimal percentOwnership ✓
  6. Live V2 Account retrieve — round-trip BigDecimal percentOwnership ✓

Note: Tests 5-6 initially failed before the JsonEncoder fix — the API returned "Expected a number as a string" because Gson was serializing BigDecimal as a JSON number.

See Also

Changelog

⚠️ V2 API decimal fields (e.g. amount on V2.Billing.MeterEvent) changed type from String to BigDecimal. Code that reads or writes these fields as String will need to use BigDecimal instead.

@jar-stripe jar-stripe requested a review from a team as a code owner March 18, 2026 22:25
@jar-stripe jar-stripe requested review from prathmesh-stripe and removed request for a team March 18, 2026 22:25
jar-stripe and others added 2 commits March 18, 2026 21:22
V2 API fields with `format: decimal` now generate as `BigDecimal` instead
of `String`. Driven by sdk-codegen#3369.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Committed-By-Agent: claude
The V2 API expects decimal fields as JSON strings (e.g., "25.5") not
JSON numbers. Add a custom Gson TypeAdapter for BigDecimal to BODY_GSON
that serializes via toPlainString().

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Committed-By-Agent: claude
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