[英]How to convert JSON response to Java List- Using Rest Assured for API Testing
我有一个嵌套的JSON响应。 JsonResponse屏幕截图
我想从列表中的第0个位置获取字典,然后从中获取一个特定的元素。 例如,作为响应{0}和{1},我希望得到完整的{0}。 然后从{0}开始,我只想提取“ Id”值。
我不想每次都使用JsonPath.read(JsonResponse String,JSON Path) 。 因此,正在寻找一些更简单,更好的选择。
如何将JSON响应转换为Java列表。 以下是响应。
Response resp = given().header("Authorization", "Bearer "+"dwded").
accept(ContentType.JSON).
when().
get("https://example.com");
return resp;
在招摇过头的编辑器宠物示例中。
responses:
200:
description: "successful operation"
schema:
type: "array"
items:
$ref: "#/definitions/Pet"
模型是从
Pet:
type: "object"
properties:
name:
type: "string"
example: "doggie"
这产生了一个java类
public class Pet {
@JsonProperty("name")
private String name = null;
该api显示了一个REST,该REST返回一个可以显示为json对象数组的实体
ResponseEntity<List<Pet>> findPetsByStatus( @NotNull@ApiParam(value = "Status values that need to be considered for filter", required = true, allowableValues = "available, pending, sold") @RequestParam(value = "status", required = true) List<String> status);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.