twilio / twilio-java

A Java library for communicating with the Twilio REST API and generating TwiML.
MIT License
477 stars 422 forks source link

fix!: Represent prices as decimal values #758

Open jon-signal opened 11 months ago

jon-signal commented 11 months ago

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