我有如下的响应json
{
"orderId": "16057421778",
"displayOrderId": "160574217786",
"numberOfItems": 2,
"items": [
{
"orderItemId": "3291379",
"item": {
"itemId": "10127763",
"definingAttrs": null,
"itemAttrs": {
"ColorLevelURLIndicator": "true"
},
"descriptiveAttrs": null,
"inventory": {
"inventoryStatus": "Available",
"lastUpdateDate": "2018-07-20T22:00:32"
},
"priceFlag": "2",
"kicId": "KIC_131-7541-1347-476"
},
"quantity": 1,
"bogoMessage": ""
},
{
"orderItemId": "3292201",
"shortSku": "628711393",
"item": {
"itemId": "10127763",
"itemAttrs": {
"ColorLevelURLIndicator": "true"
},
"descriptiveAttrs": null,
"inventory": {
"inventoryStatus": "Available",
"lastUpdateDate": "2018-07-20T22:00:32"
},
"priceFlag": "2",
"imageId": "anf_175595_02",
"kicId": "KIC_131-7541-1347-476"
},
"quantity": 1,
"bogoMessage": ""
}
],
"payment": null
}
现在我有一个像JsonArray
的{{1}},我想验证这两个键在响应中没有空值或空值。
我知道我可以使用数组值对响应进行迭代,但是如果响应很大并且需要声明["orderId","displayOrderId"]
个值,那将浪费很多时间。
我正在使用n
和RestAssured
进行验证
答案 0 :(得分:0)
您必须实现休眠验证器注释
@NotNull(来自Bean验证)(需要使用Hibernate Validator之类的验证提供程序来执行验证)。
例如,我共享一个模型类。像这样共享所有验证
public class PartnerReq {
private Integer id;
@NotEmpty
@Size(min=4, message="{NotEmpty.user.name}")
private String name;
@NotEmpty
@Email(message ="{NotEmpty.user.email}")
private String email;
@NotEmpty
@Size(min=10, max= 10, message = "{NotEmpty.user.phone}")
@Pattern(regexp = "[0-9]+")
private String phone;
@NotEmpty
private String title;
@NotEmpty
private String instituteName;
@NotEmpty
private String description;
@DateTimeFormat(pattern="dd/MM/yyyy")
@NotNull
@Past
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd/MM/yyyy")
private Date activeTo;
@DateTimeFormat(pattern="dd/MM/yyyy")
@NotNull
@Future
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd/MM/yyyy")
private Date activeFrom;
@NotNull
private Boolean notify;
@NotNull
private Boolean loginStauts;
private MultipartFile file;
//Setter and Getter
}