From 099d2ac65d72300ceeb2d629f2402981a6a42b2c Mon Sep 17 00:00:00 2001 From: Auston Bunsen Date: Wed, 15 Apr 2026 15:29:08 -0400 Subject: [PATCH] Parse LedgerItem.amount from JSON string Rails serializes BigDecimal as a JSON string (e.g. `"-49.0"`) to preserve precision, but the SDK typed `LedgerItem.Amount` as a raw decimal, causing `GetLedgerItemsAsync` to throw JsonException on real API responses. Adds `JsonNumberHandling.AllowReadingFromString` so the property reads both number and string forms, plus a test covering the string case. --- AccessGridTest/ConsoleServiceTests.cs | 25 +++++++++++++++++++++++++ src/AccessGrid/Models.cs | 1 + 2 files changed, 26 insertions(+) diff --git a/AccessGridTest/ConsoleServiceTests.cs b/AccessGridTest/ConsoleServiceTests.cs index cd792e8..a993af0 100644 --- a/AccessGridTest/ConsoleServiceTests.cs +++ b/AccessGridTest/ConsoleServiceTests.cs @@ -565,6 +565,31 @@ public async Task GetLedgerItemsAsync_ReturnsLedgerItemsWithNestedObjects() Assert.That(result.Pagination.TotalCount, Is.EqualTo(1)); } + [Test] + public async Task GetLedgerItemsAsync_ParsesAmountFromJsonString() + { + // Rails serializes BigDecimal as a JSON string, not a number. + var json = """ + { + "ledger_items": [ + { + "created_at": "2025-06-15T14:30:00Z", + "amount": "-1.50", + "id": "li_abc123", + "kind": "access_pass_debit" + } + ], + "pagination": { "current_page": 1, "per_page": 50, "total_pages": 1, "total_count": 1 } + } + """; + StubHttpResponse(json); + + var result = await _client.Console.GetLedgerItemsAsync(); + + Assert.That(result.LedgerItems, Has.Count.EqualTo(1)); + Assert.That(result.LedgerItems[0].Amount, Is.EqualTo(-1.50m)); + } + [Test] public async Task GetLedgerItemsAsync_PassesDateFilters() { diff --git a/src/AccessGrid/Models.cs b/src/AccessGrid/Models.cs index acce0a3..3d812cc 100644 --- a/src/AccessGrid/Models.cs +++ b/src/AccessGrid/Models.cs @@ -778,6 +778,7 @@ public class LedgerItem public DateTime? CreatedAt { get; set; } [JsonPropertyName("amount")] + [JsonNumberHandling(JsonNumberHandling.AllowReadingFromString)] public decimal Amount { get; set; } [JsonPropertyName("id")]