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:
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.
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)
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:
double
toBigDecimal
. The existing getters are unchanged and return adouble
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