Maciej Treder
Maciej Treder

Reputation: 12342

(RestAssured) Extract nested path as given type

Let's say I have following model:

@Data
class Model {
    private String someField;
    private String otherField;
}

And following JSON response in RestAssured:

{
     wrapperField: {
          someField: "some value",
          otherField: "other value"
     }
}

Is it possible to use extract().as() construction in the nested path?

Something like:

getService().get("my-endpoint").then().extract("wrapperField").as(Model.class)

Upvotes: 1

Views: 1621

Answers (1)

Lakitu Lakitutu
Lakitu Lakitutu

Reputation: 278

Have you tried something less elegant? Like that:

Response r = given()
            .when()
            .get(url)
            .then()
            .extract()
            .response();

r.getBody().jsonPath().getObject("path", Model.class);

Upvotes: 2

Related Questions