放心post连载json正文
rest assured post serialization json body
我如何使用 swagger 中声明的数据?据我所知,我现在可以在没有 [] 的情况下使用。我该如何添加它?
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;
}
放心的方法是:
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": "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 用法示例
dtoList
[
{
"origin": "string",
"roleID": "string",
"roleName": "string",
"userOrGroupID": "string"
}
]
您可以将 JSONObject
放入列表中。
.body(assignmentBody)
-->
.body(Arrays.asList(assignmentBody))
我如何使用 swagger 中声明的数据?据我所知,我现在可以在没有 [] 的情况下使用。我该如何添加它?
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;
}
放心的方法是:
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": "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 用法示例
dtoList
[
{
"origin": "string",
"roleID": "string",
"roleName": "string",
"userOrGroupID": "string"
}
]
您可以将 JSONObject
放入列表中。
.body(assignmentBody)
-->
.body(Arrays.asList(assignmentBody))