0

我有如下响应 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类似的东西["orderId","displayOrderId"],我想验证这两个键没有空值或空值作为响应。

我知道我可以使用数组值迭代响应,但是如果响应非常大并且我有n许多值要断言,那将浪费大量时间。

我正在使用RestAssuredJsonPath验证

4

1 回答 1

0

你必须实现休眠验证器注释

来自 Bean Validation 的 @NotNull(需要像 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
}
于 2018-08-13T11:59:46.580 回答