how can i use data as it is stated in swagger? as i understand now i can use without []. how can i add it?
public static JSONObject assignmentList(String rolename) {
JSONObject requestParams = new JSONObject();
requestParams.put("origin", "LOCAL");
requestParams.put("roleID", roleId);
requestParams.put("roleName", rolename);
requestParams.put("userOrGroupID", userId);
return requestParams;
}
rest assured method is:
public static void addAssignment(String rolename) {
JSONObject assignmentBody = assignmentList(rolename);
localLogin.localLogin("superadmin","Smoke.1234");
res = given()
.header("Authorization", "Bearer " localLogin.accessToken)
.header("Content-type", "application/json")
.contentType(ContentType.JSON)
.accept(ContentType.JSON)
.body(assignmentBody)
.when()
.post("https://localhost:8090/api/v1/user-role-assignments")
.then().contentType(ContentType.JSON).log().all().statusCode(201).extract().response();
error when execute;
"error": "JSON parse error: Cannot deserialize instance of `java.util.ArrayList...........` out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.util.ArrayList<............tDTO>` out of START_OBJECT token\n at [Source: (PushbackInputStream); line: 1, column: 1]",
Swagger dto usage example
dtoList
[
{
"origin": "string",
"roleID": "string",
"roleName": "string",
"userOrGroupID": "string"
}
]
CodePudding user response:
You can put the JSONObject
in a List.
.body(assignmentBody)
-->
.body(Arrays.asList(assignmentBody))