Skydiver, this is a follow-on from my previous query, I'm now trying to handle a response containing 10 occurrences of the Employee record. I'm having some challenges bridging the COBOL world where Records and Fields map an area of memory, and the .NET world of reference and value classes. How do I get data into the array class JZ_Employee?
The Response classes are defined like this: -
The point of this is that it will be much quicker to return a chunk of records in one request/response, and only go back to the service when the next chunk is required. The first test however reads Employee by its 1ry key, and should return only one record and 9 "empty" JSON records.
A ReadyAPI test reading Employee by its 1ry key shows that 10 occurrences of JZ-Employee are returned, with data in the first and empty JSON in the rest. This is correct. Next step: handle this with my own code.
With the same test parameters, method JSPG2AClient.ReqestRespond sends the request to the service, which responds through code: -
AssignResponseToProperties fails on the first statement attempting to assign an array value: -
Debugging shows that although the scalar classes all have values, the array classes are all null
The response is created by the statement above
Result is properly-formed JSON, containing 10 occurrences of JZ_Employee with data in the first and empty JSON in the rest. Exactly as I had expected. I saved and displayed the JSON, it shows
This StackOverflow article suggests that I need to use <List<JZ_Employee_>> to deserialize the array class, but of course that's only part of <ResponseJSPG2A> and so of course <List<ResponseJSPG2A>> is not valid. Help.
Thank you, Robert.
The Response classes are defined like this: -
C#:
namespace MyJSv
{
public class ResponseJSPG2A
{
public class JSPG2AResponse_
{
public class OJSPG2A_
{
...
public int JZ_Employee_BrowseCount { get; set; }
// and more scalar classes,
public class JZ_Employee_
{
public string JZ_Employee_NthReturnCode { get; set; }
public string EMPNO { get; set; }
// and more classes within the Employee record
}
public JZ_Employee_[] JZ_Employee { get; } = new JZ_Employee_[10];
}
public OJSPG2A_ OJSPG2A { get; } = new OJSPG2A_ ();
}
public JSPG2AResponse_ JSPG2AResponse { get; } = new JSPG2AResponse_ ();
}
}
The point of this is that it will be much quicker to return a chunk of records in one request/response, and only go back to the service when the next chunk is required. The first test however reads Employee by its 1ry key, and should return only one record and 9 "empty" JSON records.
A ReadyAPI test reading Employee by its 1ry key shows that 10 occurrences of JZ-Employee are returned, with data in the first and empty JSON in the rest. This is correct. Next step: handle this with my own code.
With the same test parameters, method JSPG2AClient.ReqestRespond sends the request to the service, which responds through code: -
C#:
if (response.IsSuccessStatusCode)
{
Response = JsonConvert.DeserializeObject<ResponseJSPG2A>(result);
AssignResponseToProperties(true);
return true;
}
AssignResponseToProperties fails on the first statement attempting to assign an array value: -
C#:
_JZ_Employee_NthReturnCode = Response.JSPG2AResponse.OJSPG2A.JZ_Employee[EmployeeSub].JZ_Employee_NthReturnCode;
Debugging shows that although the scalar classes all have values, the array classes are all null
The response is created by the statement above
C#:
Response = JsonConvert.DeserializeObject<ResponseJSPG2A>(result);
Result is properly-formed JSON, containing 10 occurrences of JZ_Employee with data in the first and empty JSON in the rest. Exactly as I had expected. I saved and displayed the JSON, it shows
JSON:
{
"JSPG2AResponse": {
"OJSPG2A": {
...
"JZ_Employee_BrowseCount": 0,
// more scalar fields
"JZ_Employee": [
{
"JZ_Employee_NthReturnCode": "U",
"EMPNO": "000060",
// other fields of first Employee
},
{
"JZ_Employee_NthReturnCode": "",
"EMPNO": "000000",
... // rest of initialized fields
},
// Another 8 empty occurrences
]
}
}
}
This StackOverflow article suggests that I need to use <List<JZ_Employee_>> to deserialize the array class, but of course that's only part of <ResponseJSPG2A> and so of course <List<ResponseJSPG2A>> is not valid. Help.
Thank you, Robert.