放心的Json Path返回异常

时间:2019-10-18 10:04:19

标签: rest-assured rest-assured-jsonpath

我正在从文件中读取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文件,我是从邮递员的回复中复制的:

{
  "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
  }
}

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

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

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