Summary MANASYS Jazz generates CICS (= mainframe) Web services as COBOL programs that communicate using JSON, and it also generates related C# interfaces that expose these services to client programs as properties and methods. Program JSPG2 responds with a single employee record, JSPG2A is a version that can return up to 10 Employee records. JSPG2 works perfectly (see this video), but JSPG2A does not.
Detail To map hierarchical COBOL record structures to C# classes, a set of nested C# classes is defined like this
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_ ();
}
}
For a single occurrence of JZ-Employee its definition is
public JZ_Employee_ JZ_Employee { get; } = new JZ_Employee_ ();
Otherwise the definition of ResponseJSPG2 and ResponseJSPG2A are the same
Newtonsoft.JSON converts the incoming JSON to C# with
Response = JsonConvert.DeserializeObject<ResponseJSPG2>(result);
and then
AssignResponseToProperties(true);
assigns data from ResponseJSPG2 to the properties that JSPG2Client wishes to expose.
This all works perfectly with ResponseJSPG2
, where there is a single Employee record. The equivalent with <ResponseJSPG2A>
where there is an array of 10 records returns 10 null records, and the equivalent AssignResponseToProperties
fails when it attempts to reference to an Employee field: -
_EMPNO = Response.JSPG2AResponse.OJSPG2A.JZ_Employee[EmployeeSub].EMPNO;
Yet Visual Studio debugging, and the same test of the web service program JSPG2A with test utility ReadyAPI, shows that JSON is returned with 10 Employee records, all containing the expected data.
Here is the JSON returned to the test, edited to remove most fields and only 2 Employee records, so that it matches the nested C# classes above: -
{
"JSPG2AResponse": {
"OJSPG2A": {
"JZ_Employee_BrowseCount": 16,
"JZ_Employee": [
{
"JZ_Employee_NthReturnCode": "F",
"EMPNO": "000060"
},
{
"JZ_Employee_NthReturnCode": "N",
"EMPNO": "000090"
}
]
}
}
}
Question
Is there a way of getting DeserializeObject to handle array classes automatically, or do I have to use Newtonsoft.Json.Linq and write logic to parse the JSON and handle the array explicitly? Or some other way of achieving my objective?