Клиент RestSharp возвращает все свойства как нулевые при десериализации ответа JSON
Я пытаюсь сделать очень простой пример использования метода Execute RestSharp для запроса конечной точки отдыха и сериализации в POCO. Однако все, что я пробую, приводит к получению объекта response.Data, который имеет все свойства со значением NULL.
Вот ответ JSON:
{
"Result":
{
"Location":
{
"BusinessUnit": "BTA",
"BusinessUnitName": "CASINO",
"LocationId": "4070",
"LocationCode": "ZBTA",
"LocationName": "Name of Casino"
}
}
}
Вот мой тестовый код
[TestMethod]
public void TestLocationsGetById()
{
//given
var request = new RestRequest();
request.Resource = serviceEndpoint + "/{singleItemTestId}";
request.Method = Method.GET;
request.AddHeader("accept", Configuration.JSONContentType);
request.RootElement = "Location";
request.AddParameter("singleItemTestId", singleItemTestId, ParameterType.UrlSegment);
request.RequestFormat = DataFormat.Json;
//when
Location location = api.Execute<Location>(request);
//then
Assert.IsNotNull(location.LocationId); //fails - all properties are returned null
}
И вот мой код API
public T Execute<T>(RestRequest request) where T : new()
{
var client = new RestClient();
client.BaseUrl = Configuration.ESBRestBaseURL;
//request.OnBeforeDeserialization = resp => { resp.ContentLength = 761; };
var response = client.Execute<T>(request);
return response.Data;
}
И наконец, вот мой POCO
public class Location
{
public string BusinessUnit { get; set; }
public string BusinessUnitName { get; set; }
public string LocationId { get; set; }
public string LocationCode { get; set; }
public string LocationName { get; set; }
}
Кроме того, свойства ErrorException и ErrorResponse в ответе имеют значение NULL.
Это кажется очень простым делом, но я бегал кругами весь день! Благодарю.