Skip to content
Advertisement

REST. Checking the type of incoming field

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?

Advertisement

Answer

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);
}
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement