【问题标题】:Rest Assured Json Path returns Exception放心的 Json 路径返回异常
【发布时间】:2020-02-15 07:33:48
【问题描述】:

我正在从文件中读取 json,以便将其与 http 请求正文的 json 进行比较。

我在做

JsonPath expectedJson = new JsonPath(new File("response.json"));
// some more code
assertThat().body("", equalTo(expectedJson.getMap("")));

导致JsonPathException: Failed to parse the JSON document

这是response.json 文件,我从 Postman 的响应中复制了该文件:

{
  "screenDefinition":{
    "taskId":"account-type",
    "parameters":null
  },
  "prospect":{
    "initializationType":"FIRST_HOLDER",
    "jointAccount":{
      "jointAccountId":655
    },
    "emailConfirmed":false,
    "addressConfirmed":false,
    "emailValidated":false,
    "smsCodeAttemptsLeft":0,
    "mobilePhoneValidated":false,
    "paragraphsAccepted":false,
    "termsConditionsAccepted":false,
    "changedToAutonomousMethod":false,
    "changedToIdentificationMethod":false,
    "contractAccepted":false,
    "prospectOnboardContactType":"NONE",
    "secondAccountHolder":false,
    "evidencesUploaded":false,
    "uploadEvidencesLater":false
  }
}

有什么想法吗?

【问题讨论】:

    标签: rest-assured rest-assured-jsonpath


    【解决方案1】:

    您得到的JsonPathException 可能是由java.io.FileNotFoundException 引起的,这意味着您的文件路径不正确。 尝试先检查文件是否存在:

    File file = new File("response.json");
    System.out.println("File exists: " + file.exists());
    JsonPath jsonPath = new JsonPath(file);
    

    【讨论】:

      猜你喜欢
      • 2019-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-14
      • 2014-07-17
      • 2020-09-01
      • 2017-08-17
      • 2013-12-16
      相关资源
      最近更新 更多