RequestSpecification request = RestAssured.given().header("Content-Type", "application/json");
JSONObject requestParams = new JSONObject();
JSONObject childObject1= new JSONObject();
JSONObject childObject2 = new JSONObject();
requestParams.put("contactClass", "ZWSS");
requestParams.put("contactActivity", "0039");
requestParams.put("contractAccountNumber", "210024144291");
requestParams.put("text", "Please rate the overall ease of using the website to initiate or make your service request");
requestParams.put("contactType", "Z1");
requestParams.put("contactDirection", "1");
childObject1.put("question", "0001");
childObject1.put("answer", "01");
childObject1.put("question", "0002");
childObject1.put("answer", "02");
requestParams.put("addInfo", childObject1);
requestParams.put("addInfo", childObject2);
request.body(requestParams.toString());
Response response = request.post("https://api-dev.adp.com/api/*/*/*");
Я пытаюсь протестировать метод Post с вложенными тегами в среде Restassured, и выше приведен фрагмент кода, в котором я строю запрос в объекте JSON.По некоторым причинам мой JSON не содержит оба значения (Вопросы и Ответы) Addinfo, и запрос не выполняется, и Запрос выполняется в следующем формате.
{"contractAccountNumber":"210024144291",
"contactClass":"ZWSS",
"contactActivity":"0039",
"contactType":"Z1",
"addInfo":{"question":"0002","answer":"02"},
"text":"Please rate the overall ease of using the website to initiate or
make your service request",
"contactDirection":"1"}
Но Запрос должен быть в следующем формате
{
"contactClass": "ZWSS",
"contactActivity": "0039",
"contractAccountNumber": "210024144291",
"text": "Please rate the overall ease of using the website to initiate or
make your service request",
"contactType": "Z1",
"contactDirection": "1",
"addInfo": [{
"question": "0001",
"answer": "01"
},
{
"question": "0002",
"answer": "02"
}
]
}
Любой может помочь мне исправить это ..