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

fix!: Represent prices as decimal values

Open jon-signal opened this issue 2 years ago • 1 comments

Fixes

The Twilio API actually returns prices as strings, but the Java SDK represents them as double values. Generally, it's best to avoid floating-point representations of monetary values, and it appears that the API itself is designed with this in mind.

This pull request:

  1. Changes the JSON in unit tests for pricing-related response objects to represent prices as strings. On its own, this has no functional effect, but does mean that the test vectors align with the real return values from the API.
  2. Changes the internal representation of prices from double to BigDecimal. The existing getters are unchanged and return a double representation of the prices. I've added new getters (e.g. getBasePriceDecimal) that return the prices as lossless decimal values.

The second change should be backward-compatible for most users, but I believe this is still technically a breaking change because it changes the constructors of those objects. Still, with the 10-series SDK going out, this may be a good time to make the change.

Checklist

  • [x] I acknowledge that all my contributions will be made under the project's license
  • [x] I have made a material change to the repo (functionality, testing, spelling, grammar)
  • [x] I have read the Contribution Guidelines and my PR follows them
  • [x] I have titled the PR appropriately
  • [x] I have updated my branch with the main branch
  • [x] I have added tests that prove my fix is effective or that my feature works
  • [x] ~I have added the necessary documentation about the functionality in the appropriate .md file~ (n/a)
  • [x] I have added inline documentation to the code I modified

jon-signal avatar Aug 11 '23 16:08 jon-signal

Friends, I recognize this may not be a top priority, but is there anything I can do to help move this along to some kind of conclusion?

jon-signal avatar May 16 '25 15:05 jon-signal