I have written code for Rest Assured API to automate, I've created the payload using JSONObject but the payload is not ordered because of which I am getting an error. Below is how my payload should look like
{
"Student": "Primary",
"class": "First",
"segments": [{
"Subject": "Science",
"Marks": "50"
},
{
"Subject": "History",
"Marks": "50"
}
],
"Fee": "Paid",
"Roll no": "20"
}
but the payload generated by the object mapper is as below
{
"Student": "Primary",
"class": "First",
"Fee": "Paid",
"Roll no": "20",
"segments": [{
"Subject": "Science",
"Marks": "50"
},
{
"Subject": "History",
"Marks": "50"
}
]
}
Below is the code written in Java
JSONObject requestParam = new JSONObject();
JSONArray requestParamArray = new JSONArray();
requestParam.put("Student", strStud);
requestParam.put("class", strClass);
Map searchReqMap1 = new LinkedHashMap(3);
searchReqMap1.put("Subject", strsubject);
searchReqMap1.put("mark", strmark);
Map searchReqMap2 = new LinkedHashMap(3);
searchReqMap2.put("Subject", strsubject);
searchReqMap2.put("mark", strmark);
requestParamArray.add(searchReqMap1);
requestParamArray.add(searchReqMap2);
requestParam.put("segments", requestParamArray);
requestParam.put("fee", strfee);
requestParam.put("rollno", strrollno);
return requestParam.toJSONString();
` Input data is read from excel