Convert a JSON String to RestAssured Response

2,666 views
Skip to first unread message

prvns

unread,
Sep 22, 2016, 4:03:58 PM9/22/16
to REST assured
I have a simple Json in Java String. I want to convert the String to RestAssured Response. Is it possible to do that? How?

prvns

unread,
Sep 22, 2016, 4:23:33 PM9/22/16
to REST assured
Or

Is it possible to convert apache HttpResponse to RestAssured Response

HttpClient httpClient = HttpClientBuilder.create().build();
            HttpPost httpPost = new HttpPost(url);
            org.apache.http.entity.StringEntity entity = new org.apache.http.entity.StringEntity(body);
            httpPost.setEntity(entity);
            httpPost.setHeader("Accept", "application/json");
            httpPost.setHeader("Content-type", "application/json");
            HttpResponse httpResponse = httpClient.execute(httpPost);

I'd like to convert httpResponse to RestAssured Response

Johan Haleby

unread,
Sep 23, 2016, 1:06:28 PM9/23/16
to rest-a...@googlegroups.com
Hi, 

There's no built-in way of converting an http response to a rest assured response although it ought to be possible implement it (feel free to contribute :)). You also cannot convert a json string to a rest assured response (that would be impossible) but you can using the JsonPath that ships with rest assured and do something like this:

String json = ...
JsonPath jsonPath = JsonPath.from(json);
String z = jsonPath.getString("x.y.z");

Hope that helps.
/Johan


--
You received this message because you are subscribed to the Google Groups "REST assured" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rest-assured+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

prvns

unread,
Sep 24, 2016, 7:28:45 AM9/24/16
to REST assured
Thanks Johan. I will try to come up with a solution to convert http response to RA response and will create a pull request.
To unsubscribe from this group and stop receiving emails from it, send an email to rest-assured...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages