Hi,
I have the following JSON response for one of my APIs:
{
"data": [
{
"encodedKey": "12345",
"id": "77",
"creationDate": "2017-01-23T13:02:56Z",
"lastModifiedDate": "2017-01-25T15:54:59Z",
"name": "Branch 1",
"phoneNumber": "",
"emailAddress": ""
}
]
}
and the following object model:
public class Branch {
@NotNull
private String id;
@NotNull
private String name;
@NotNull
@Past
private Date creationDate;
@NotNull
private Date lastModifiedDate;
private String phoneNumber;
@Email
private String emailAddress;
// getters & setters
}
My question is if there's a possible solution to serializing/deserializing other than wrapping the Branch into another class (e.g. "BranchWrapper") containing a List of Branches. This would be tedious to do for all my objects.
If would be very handy to be able to do something like below:
Branch branchBasic = given().pathParam("id", branchId)
.when()
.get("/branches/{id}")
.then()
.rootPath("data[0]") // would extract the Response starting with the given root path
.extract()
.as(Branch.class);
Any alternatives?
Thanks,