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 issue - RestSharp does not use Newtonsoft JsonNetSerializer by default #49

Open
tw17 opened this issue May 13, 2021 · 1 comment

Comments

@tw17
Copy link

tw17 commented May 13, 2021

All of the API entities rely on the Newtonsoft JsonProperty attribute to serialize correctly. By default RestSharp does not use Newtonsoft JsonNetSerializer which means the request body does not get serialized with the correct property names

For example nexus_addresses should look like this:

"nexus_addresses": [{
    "id": null,
    "country": "US",
    "zip": null,
    "state": "AZ",
    "city": null,
    "street": null
}],

instead it gets serialized (When using the NexusAddress class instead of just a dynamic) as:

"nexus_addresses": [{
    "Id": null,
    "Country": "US",
    "Zip": null,
    "State": "AZ",
    "City": null,
    "Street": null
}],

Notice the casing.

This caused the API to return incorrect tax information as I'm assuming the nexus addresses do not get deserialized properly and are required for my use case.

To fix this we could set the Serializer when building the RestRequest Note: you will need to reference the package RestSharp.Serializers.NewtonsoftJson

var request = new RestRequest(action, method)
{
      RequestFormat = DataFormat.Json, JsonSerializer = new JsonNetSerializer()
};
@tw17
Copy link
Author

tw17 commented May 13, 2021

PR Here

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