RestSharp returning JSON element as object instead of array

81 views Asked by At

I send a JSON request to an API. The response contains an Alert element that is defined as an array. However, if Alert contains only one element, RestSharp returns it as an object.

JSON response, shortened:

{
   ...
   "Alert": {
       "Code": "110971",
       "Description": "Your invoice may vary from the displayed reference rates"
   },
   ...
}

If the same request is sent with Postman, the Alert element of the response is correctly returned as an array with only one element.

JSON response, shortened:

{
   ...
   "Alert": [
       {
           "Code": "110971",
           "Description": "Your invoice may vary from the displayed reference rates"
       }
   ],
   ...
}

Is there a way to get the correct response (Alert as array) with RestSharp, too?

I'm using RestSharp 106.10 and .NET Framework 4.8. RestSharp 106.15 shows the same behaviour and I cannot upgrade to a newer version.

Changing the definition of the response class for deserialization is no option. If the "Alert" contains two or more elements, it is correctly returned as array.

0

There are 0 answers