1

I see that I can do the following with restassured. Given JSON:

{"locationId"=456,"name"="Home"}

I can get an object representing that json like this:

Location location = given().headers(headers).when().expect().statusCode(200).get(getUrl(urlQualifier)).as(Location.class);

How do I parse this JSON is I receive a root array of my Location objects in JSON. So, given this JSON:

[{"locationId"=1,name="Home"},{"locationId"=2,name="Work"}]

I want to parse out a List object. The following of course is a compile error, but it demonstrates what I am trying to do:

List<Location> list = given().headers(headers).when().expect().statusCode(200).get(getUrl(urlQualifier)).as((List<Location>).class);
2
  • 1
    your format for json is not correct : Commented May 23, 2013 at 1:17
  • {locationId=456,name="Home"} is not valid JSON. This is: {"locationId":456,"name":"Home"}. Commented May 23, 2013 at 1:20

1 Answer 1

3

Try deserializing it to a Java array:

Location[] list = given().headers(headers).when().expect().statusCode(200).get(getUrl(urlQualifier)).as(Location[].class);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.