Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serialization error: Cannot get the value of a token type 'StartObject' as a string. #5

Open
othman-birem opened this issue Oct 27, 2024 · 0 comments

Comments

@othman-birem
Copy link

I am facing an error which i assume is out of my hand (in case where i happen to not be missing anything obvious).
For context i am using the .net 6.0 package on a desktop application ,everything works fine except one specific case, the problem occurs when my checkout has a shipping address and i call the API to GET it i get the following error:

InvalidOperationException: Cannot get the value of a token type 'StartObject' as a string.
JsonException: The JSON value could not be converted to System.String. Path: $.shipping_address | LineNumber: 0 | BytePositionInLine: 704.

Now i am familiar with this the first part of the error which means frankly that the runtime was expecting a plain ordinary string but instead got a more complex object of another type.
Hence, i assume the example could be that the expected ShippingAddress value should be something like:
ShippingAddress: "Algeria, Algiers"
but instead something like the following is received:

{
       country: "Algeria",
       state: "Algeirs"
}

I have tried multiple approaches to solve the issue but nothing of the mentioned worked, it's an INTERNAL error quite frankly.

PS note, my checkouts are created with the CollectShippingAddress field set to false, but after i redirect the client to the payment land page and the payment is done, somehow the country field on the checkout's shipping address are set to Algeria out of my will and that's what causes the later-on error.
Also, the country field is set only when the Payment is effectuated, meaning neither on cancel/expire... ect.

At last, here is the function that causes the error, which like i said does not work only when shippingAddress is not null:

internal async Task<CheckoutResponse?> GetMyCheckout()
{
    return string.IsNullOrEmpty(appConfig.LastCheckoutID) ? null : (await chargilyClient.GetCheckout(appConfig.LastCheckoutID)).Value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant