Home > Software engineering >  REST. Checking the type of incoming field
REST. Checking the type of incoming field

Time:07-13

how can I check the field type of the incoming response to the REST request.

For example, I receive an answer with the "pay" field:"1000" I want to check that the incoming field, its value is of type int What verification methods are there?

CodePudding user response:

You can use Rest Assured

Say you have this endpoint: https://mocki.io/v1/0f2701f8-46ab-48b5-9584-7e58da29498d

that returns:

{
  "pay": 1000
}

Then your code could be:

public static void main(String[] args) throws URISyntaxException {
    System.out.println(RestAssured
            .get(new URI("https://mocki.io/v1/0f2701f8-46ab-48b5-9584-7e58da29498d"))
            .jsonPath()
            .get("pay") instanceof Integer);
}
  • Related