I'm trying to make a GET request to a REST api which returns a JSON. This is what I have right now:
RestClient client = new RestClient(BASE_URL);
var request = new RestRequest(CONTROLLER_PATH);
var response = await client.GetAsync<MyDtoClass[]>(request);
When this code executes, response
is an array of MyDtoClass
but the fields in each element of the array are null
. If instead, I run this code (I removed the generic):
RestClient client = new RestClient(BASE_URL);
var request = new RestRequest(CONTROLLER_PATH);
var response = await client.GetAsync(request);
then response
is a string represintation of the JSON that BASE_URL CONTROLLER_PATH
returns (nothing is null).
What is the idiomatic way to make a request to this REST api and convert the response into an array of MyDtoClass
. Also, if anyone has suggestions for a library you think is better then RestSharp, please share.
Thank you in advance.
CodePudding user response:
The issue was that MyDtoClass
had fields instead of properties.