stripe-java icon indicating copy to clipboard operation
stripe-java copied to clipboard

`toJson` fails to create exactly the same json as the Stripe HTTP API

Open decoursin opened this issue 1 year ago • 3 comments

Describe the bug

The InvoiceLineItem.getUnitAmountExcludingTax returns a BigDecimal. While the Stripe API HTTP Server returns the unit_amount_excluding_tax as a string.

As a result, when the InvoiceLineItem is serialized using toJson, it returns a completely different format than the Stripe API Http Server. They should be the same.

To Reproduce

  1. Create an invoice and 1 invoice item.
  2. Serialize that invoice using toJson.
  3. View the serialize invoice item, and see that it's serialized as a json number rather than a string.

Expected behavior

Serializing an InvoiceLineItem using toJson is suppose to replicate the Stripe API HTTP server 100% exactly, and it's not doing that.

Code snippets

No response

OS

All

Java version

Java 17

stripe-java version

v26.4.0

API version

2024-06-20

Additional context

No response

decoursin avatar Aug 06 '24 14:08 decoursin

Thanks for filing! We've copied to our internal bug tracker and will address it when we have a chance.

xavdid-stripe avatar Aug 07 '24 23:08 xavdid-stripe

Great, thank you

decoursin avatar Aug 08 '24 06:08 decoursin

I'm using stripe sdk models to build mocks and stubs.

I observe the same issue with unit_amount_decimal and other similar fields. Moreover, some BigDecimal values want to be treated as numbers (e.g., percent_off in coupon details). This dichotomy means that I cannot simply create a type adapter to serialize all BigDecimal values as strings.

It's a major blocker for autotests.

Maybe there is some workaround I'm not aware of?

parfentjev avatar Aug 26 '25 10:08 parfentjev