feat(ledger): serialize api money amounts as decimal strings - #114
Merged
Conversation
Money amounts were serialized as JSON numbers, which JS and other JSON clients truncate to float64, losing precision for large or high-scale NUMERIC(38,18) values. Add MoneyAmountSerializer writing BigDecimal via toPlainString (exact digits, preserved scale, no scientific notation) and apply it to BalanceResponse.amount with @Schema(type=string) so the generated OpenAPI matches. Input is unaffected; default deserialization already accepts string and number. Closes #113
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Money amounts were serialized over the API as JSON numbers. JSON has one numeric type and JS clients parse it into float64, truncating large or high-scale
NUMERIC(38,18)values before any client code runs - a ledger correctness hazard.This serializes money amounts as JSON decimal strings via
BigDecimal.toPlainString()(exact digits, preserved scale, never scientific notation):Scope
MoneyAmountSerializer (JsonSerializer<BigDecimal>)BalanceResponse.amount(the only money output field today) +@Schema(type=string, format=decimal)so generated OpenAPI is accurateBigDecimaldeserialization already accepts string and numberTests
MoneyAmountSerializerTest: trailing zeros preserved (100.00->"100.00"); high-scale value12345678901234567890.123456789012345678round-trips losslessly with no exponentAccountControllerTestbalance assertion updated to the string form (validates the real Spring ObjectMapper path)Unblocks Sandbox UI Screen 2 (Account Detail + Balance) on a lossless string amount. ADR: Money over JSON (prepared for Wiki).
Closes #113