Dwolla / dwolla-v2-csharp

Official C# Wrapper for Dwolla's API
https://developers.dwolla.com
MIT License
12 stars 15 forks source link

ResponseBuilder Can't Deserialize JSON "Value" to Decimal #56

Open StevP116 opened 1 year ago

StevP116 commented 1 year ago

In an attempt to retrieve a transfer from sandbox, using the Dwolla TransferResponse model, when I hit the GET https://api.dwolla.com/transfers/{id} endpoint, I get the following DeserializationException with error response:

The JSON value could not be converted to System.Decimal. Path: $.amount.value | LineNumber: 0 | BytePositionInLine: 1174.

This is the JSON amount data:

"amount": {
    "value": "31.25",
    "currency": "USD"
  }

The DeserializationException is coming from the ResponseBuilder. It is using a JsonSerializerOptions object that isn't configured to handle quoted numbers. The JsonSerializerOptions that the RestClient and ResponseBuilder are using is configured in the DwollaClient. Therefore, I don't believe there is anything we can do on our end to remedy this issue.

Seems like a pretty simple fix would be to configure the default JsonSerializerOptions with NumberHandling = JsonNumberHandling.AllowReadingFromString.

StevP116 commented 1 year ago

As a follow-up, this might be really nice to have as well.

StevP116 commented 1 year ago

Update: We found a workaround by creating an instance of RestClient and passed in a customized JsonSerializerOptions object, then used reflection to invoke the internal DwollaClient constructor. Even still, having a fix for this would be nice, as using reflection is not ideal.

jacob-ezlandlord commented 2 days ago

We have been using version 5.4.0 of the Dwolla client with no issues, but when we tried to upgrade to the latest stable version (6.0.0), it seems like this bug was reintroduced.

We encountered the same deserialization error trying to hit funding-sources/{id}/balance and convert the response content to a BalanceReponse.

Is this known to still be an issue? Is it being addressed?

P.S. The reason we are trying to upgrade to the latest stable version is in light of Dwolla's upcoming changes involving HTTP/2. They seem to recommend updating to the latest versions of their clients to ensure we can handle their updates. It would be great if someone could comment on whether version 5.4.0 of this client is sufficient to be prepared for Dwolla's upcoming updates.