I have an API which expected to return result as below (which holds the data fetched from Cosmos DB)
public class ConsumerResponse
{
public string ObjectId { get; set; }
public string ConsumerType { get; set; }
public object Data { get; set; }
}
I am using postman to test this API. Below is the API function which returns CustomerResponse object
[HttpGet]
[Route("{container}/{consumerType}/{objectId}")]
[ProducesResponseType(typeof(ConsumerResponse), (int)HttpStatusCode.OK)]
[ProducesResponseType(typeof(ErrorResponse), (int)HttpStatusCode.BadRequest)]
[ProducesResponseType(typeof(ErrorResponse), (int)HttpStatusCode.InternalServerError)]
public async Task<ConsumerResponse> Get(string container , string consumerType, string objectId)
{
var response = await _messageProcessingService.GetAsync(container, consumerType, objectId);
return response;
}
When I debug the code, I can see all the valid data mapped to each propery in CustomerResponse class. The "Data" is nested object. However when I call this API in Postman the nested values of "Data" object becomes empty as below
{
"objectId": "8bea9894-8685-46e4-8637-5614e624b05e",
"consumerType": "Patient",
"data": {
"name": [
[
[]
],
[
[]
],
[
[]
],
[
[]
]
],
"gender": [],
"birthDate": [],
"countryCode": [],
"isActive": [],
"consumerConsent": [],
"accountStatus": [
[
[
[]
]
]
]
}
}
However if I change the data type of "Data" as string then I am getting result as below
{
"objectId": "8bea9894-8685-46e4-8637-5614e624b05e",
"consumerType": "Patient",
"data": "{\r\n \"name\": {\r\n \"use\": \"Official\",\r\n \"surname\": \"Dope\",\r\n \"firstName\": \"Johny\",\r\n \"prefix\": \"Mr.\"\r\n },\r\n \"gender\": \"Male\",\r\n \"birthDate\": \"1991-02-02\",\r\n \"countryCode\": \"IN\",\r\n \"isActive\": false,\r\n \"consumerConsent\": true,\r\n \"accountStatus\": [\r\n {\r\n \"startDate\": \"2021-09-08T09:27:21.1946786+10:00\"\r\n }\r\n ]\r\n}"
}
How do I get the values for nested structure when I use Object data type?
-Alan-
public object Datais very suspicious