Rest Assured - Extract JSON to Java List

If I’ve not used Rest Assured for a while I always forget how to extract a Java List, and not an Array, from a JSON API response.

It’s fairly easy, you just have to remember to use jsonPath rather than as. I always love an example, so here we are:

    public List<BookingID> bookings() {
        return getRequestSpec()
                .when()
                .get("https://restful-booker.herokuapp.com/booking")
                .then()
                .extract()
                .body()
                // here's the magic
                .jsonPath().getList(".", BookingID.class);
    }