El cliente RestSharp devuelve todas las propiedades como nulas al deserializar la respuesta JSON
Estoy tratando de hacer un ejemplo muy simple de usar el método Execute de RestSharp para consultar un punto final de descanso y serializar a un POCO. Sin embargo, todo lo que intento da como resultado un objeto response.Data que tiene todas las propiedades con un valor NULL.
Aquí está la respuesta JSON:
{
"Result":
{
"Location":
{
"BusinessUnit": "BTA",
"BusinessUnitName": "CASINO",
"LocationId": "4070",
"LocationCode": "ZBTA",
"LocationName": "Name of Casino"
}
}
}
Aquí está mi código de prueba
[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
}
Y aquí está mi código 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;
}
Y finalmente, aquí está mi 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; }
}
Además, las propiedades ErrorException y ErrorResponse en la respuesta son NULL.
Esto parece un caso muy simple, ¡pero he estado corriendo en círculos todo el día! Gracias.