Skip to content

Commit

Permalink
DEV-1625: Fix Issue #56: JSON Deserialization Issue for Amount Values (
Browse files Browse the repository at this point in the history
  • Loading branch information
ShreyaThapa authored Nov 5, 2024
1 parent b174ec1 commit 91261b6
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Dwolla.Client.Tests/DwollaClientShould.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class DwollaClientShould
{
private const string JsonV1 = "application/vnd.dwolla.v1.hal+json";
private const string RequestId = "some-id";
private const string UserAgent = "dwolla-v2-csharp/6.0.0";
private const string UserAgent = "dwolla-v2-csharp/6.0.1";
private static readonly Uri RequestUri = new Uri("https://api-sandbox.dwolla.com/foo");
private static readonly Uri AuthRequestUri = new Uri("https://accounts-sandbox.dwolla.com/foo");
private static readonly Headers Headers = new Headers { { "key1", "value1" }, { "key2", "value2" } };
Expand Down
8 changes: 4 additions & 4 deletions Dwolla.Client/Dwolla.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
<Company>Dwolla, Inc.</Company>
<!-- Also update UserAgent version in DwollaClient.cs -->
<AssemblyVersion>6.0.0</AssemblyVersion>
<FileVersion>6.0.0</FileVersion>
<Version>6.0.0</Version>
<AssemblyVersion>6.0.1</AssemblyVersion>
<FileVersion>6.0.1</FileVersion>
<Version>6.0.1</Version>
<Authors>Dwolla, Inc</Authors>
<Description>Official C# Wrapper for Dwolla's API v2</Description>
<Copyright>Copyright © 2018 Dwolla, Inc</Copyright>
Expand All @@ -17,4 +17,4 @@
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
<PackageReference Include="System.Text.Json" Version="7.0.1" />
</ItemGroup>
</Project>
</Project>
17 changes: 9 additions & 8 deletions Dwolla.Client/DwollaClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,16 @@ public class DwollaClient : IDwollaClient
{
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
PropertyNameCaseInsensitive = true,
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
NumberHandling = JsonNumberHandling.AllowReadingFromString
};

private static readonly string ClientVersion = typeof(DwollaClient).GetTypeInfo().Assembly
.GetCustomAttribute<AssemblyFileVersionAttribute>().Version;
#if NET5_0_OR_GREATER
private static readonly HttpClient StaticHttpClient = new HttpClient(
new SocketsHttpHandler
{
new SocketsHttpHandler
{
PooledConnectionLifetime = TimeSpan.FromMinutes(2),
SslOptions = new SslClientAuthenticationOptions { EnabledSslProtocols = SslProtocols.Tls12 }
}
Expand All @@ -58,7 +59,7 @@ public class DwollaClient : IDwollaClient
private static HttpClientHandler _staticClientHandler;
private static DateTime _staticClientHandlerExpirationDate;
#endif

private readonly IRestClient _client;

static DwollaClient()
Expand All @@ -67,7 +68,7 @@ static DwollaClient()
SetupHttpClientDefaults(StaticHttpClient);
#endif
}

public static DwollaClient Create(bool isSandbox) =>
new DwollaClient(new RestClient(JsonSettings), isSandbox);

Expand Down Expand Up @@ -152,7 +153,7 @@ internal DwollaClient(IRestClient client, bool isSandbox)
_client = client;
ApiBaseAddress = isSandbox ? "https://api-sandbox.dwolla.com" : "https://api.dwolla.com";
}

private static void SetupHttpClientDefaults(HttpClient client)
{
client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("dwolla-v2-csharp", ClientVersion));
Expand All @@ -168,7 +169,7 @@ internal static HttpClient CreateHttpClient()
_staticClientHandler.SslProtocols = SslProtocols.Tls12;
_staticClientHandlerExpirationDate = DateTime.UtcNow + TimeSpan.FromMinutes(2);
}

var client = new HttpClient(_staticClientHandler);
SetupHttpClientDefaults(client);
return client;
Expand All @@ -178,4 +179,4 @@ internal static HttpClient CreateHttpClient()
#endif
}
}
}
}
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ $ docker run --init -it dwolla/csharp-example-app:latest

## Changelog

- [**6.0.1**](https://github.com/Dwolla/dwolla-v2-csharp/releases/tag/6.0.1)
- Fix issue [#56](https://github.com/Dwolla/dwolla-v2-csharp/issues/56) reported by [@StevP116](https://github.com/StevP116) and [@jacob-ezlandlord](https://github.com/jacob-ezlandlord), addressing a deserialization bug where quoted numeric values in responses (such as `amount.value`) caused a `DeserializationException`. The `JsonSerializerOptions` in `DwollaClient` has been updated with `JsonNumberHandling.AllowReadingFromString` to support both quoted and unquoted numeric values, ensuring compatibility with varied API responses.
- Backward Compatibility - This update does not introduce any breaking changes, allowing existing integrations to continue functioning without modifications.
- Thanks to [@StevP116](https://github.com/StevP116) for recommending a straightforward fix and to everyone who contributed insights. 🎉
- File Name Correction: Renamed `LableLedgerEntry.cs` to `LabelLedgerEntry.cs` to fix a typo in the file name. This change does not impact the functionality of existing integrations.
- [**6.0.0**](https://github.com/Dwolla/dwolla-v2-csharp/releases/tag/6.0.0)
- Fix issue [#41](https://github.com/Dwolla/dwolla-v2-csharp/issues/47) reported by,
[@waynebrantley](https://github.com/waynebrantley)
Expand All @@ -192,7 +197,7 @@ $ docker run --init -it dwolla/csharp-example-app:latest
[Microsoft's HttpClient guidelines for .NET](https://learn.microsoft.com/en-us/dotnet/fundamentals/networking/http/httpclient-guidelines#recommended-use).
- Special thanks to [@natehitz](https://github.com/natehitze) and
[@IsaiahDahlberg](https://github.com/IsaiahDahlberg) for their contributions to this release!
:raised_hands:
🙌
- [**5.4.0**](https://github.com/Dwolla/dwolla-v2-csharp/releases/tag/5.4.0)
- Fix issue with deserialization of `200 Ok` response with an `_embedded` error on GET customer.
Issue [#47](https://github.com/Dwolla/dwolla-v2-csharp/issues/47). (Thanks,
Expand Down

0 comments on commit 91261b6

Please sign in to comment.