0

error image that show value is not getting populated from jsonBelow given is json file used for comparison assume It is having 2 copies which are getting compared

{
  "FileInformation": [
    {
      "ProductCode": "",
      "MaterialName": "",
      "GneBatchNum": "3336515",
      "VendorName": "abc",
      "MfgBatchNum": "2122866",
      "GneReceiveDate": "19-Aug-08",
      "DocumentDate": "20-Apr-2018",
      "FileName": "0C8B03C08BF2B8DDA13E75168E888D22.pdf",
      "documentURL": "https://hostname/csp/ui/#!/doc/c0b7cc29-e263-4b47-b420-608dbf0bed96A",
      "extracted_text": "Print timestamp: 17-Oct-2019 20:20:56"
    }
  ],
  "MaterialParameters": [
    {
      "Attribute": "1 Amino Acid Quantitative Amino Acids Quantified",
      "Specification": "Acceptable",
      "Method": "",
      "Units": "",
      "Result": "Acceptable"
    },
    {
      "Attribute": "2 Appearance White to Tan Powder",
      "Specification": "Acceptable",
      "Method": "",
      "Units": "",
      "Result": "Acceptable"
    }
  ]
}

Java code responsible to compare I am using skyscreamer jsonassert Customization for ignoring a attribute in comparision.

@Then("^Compare and validate the expected downloaded Json with actual Json$")
public void compare_files_Json(DataTable path) {
    scenario.log("Compare json files initiated");
    try {
        List < Map < String, String >> responseMessageMap = path.asMaps(String.class, String.class);
        String expectedrespath = responseMessageMap.get(0).get("expected");
        String projectId = responseMessageMap.get(0).get("projectId");
        String bucketName = responseMessageMap.get(0).get("bucketName");
        String directoryPrefix = responseMessageMap.get(0).get("directoryPrefix");
        String objectName = responseMessageMap.get(0).get("objectName");
        String filePath = responseMessageMap.get(0).get("filePath");
        String outputrequest = CloudStorageFileProcessingUtil.downloadObject(projectId, bucketName, directoryPrefix,
            objectName, filePath);
        // Reading data from input json payload
        String expectedresult = new String(Files.readAllBytes(Paths.get(expectedrespath)));

        scenario.log("------------------------------------------");
        scenario.log("Expected Exceptions are as below:");
        scenario.log(expectedresult);
        scenario.log("------------------------------------------");
        scenario.log("Actual Exceptions are as below:");
        scenario.log(outputrequest);
        // Comparing input and output json data

        JSONComparator com = new CustomComparator(JSONCompareMode.STRICT, new Customization("FileInformation.[0].documentURL", (o1, o2) - > true));
        JSONAssert.assertEquals(expectedresult, outputrequest, com);
    } catch (Exception e) {
        scenario.log("Exception occured:" + e);
        Assert.fail("Exception occurred while Json file comparison");
    }
}

and the error while accessing the field "documentURL" for ignoring during comparison is [enter image description here](https: //i.stack.imgur.com/tJiw1.png)

    I have tried below trees also but nothing is working FileInformation.[0].documentURL and FileInformation.documentURL and[0].FileInformation.documentURL

    please suggest me
    if am doing any mistake in accessing the json Attribute

0 Answers0