File tree Expand file tree Collapse file tree
src/test/java/org/baeldung/rest Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44
55
66### Relevant Articles:
7+ - [ Test a REST API with Java] ( http://www.baeldung.com/2011/10/13/integration-testing-a-rest-api/ )
Load diff This file was deleted.
Original file line number Diff line number Diff line change 22
33import java .io .IOException ;
44
5- import org .apache .commons .io .IOUtils ;
65import org .apache .http .HttpResponse ;
6+ import org .apache .http .util .EntityUtils ;
77
8- import com .google .common .base .Preconditions ;
8+ import com .fasterxml .jackson .databind .DeserializationFeature ;
9+ import com .fasterxml .jackson .databind .ObjectMapper ;
910
1011public class RetrieveUtil {
1112
12- public static String retrieveJsonFromResponse (final HttpResponse response ) throws IOException {
13- Preconditions .checkNotNull (response );
14-
15- return IOUtils .toString (response .getEntity ().getContent ());
16- }
13+ // API
1714
1815 public static <T > T retrieveResourceFromResponse (final HttpResponse response , final Class <T > clazz ) throws IOException {
19- Preconditions .checkNotNull (response );
20- Preconditions .checkNotNull (clazz );
21-
22- final String jsonFromResponse = retrieveJsonFromResponse (response );
23- return ConvertUtil .convertJsonToResource (jsonFromResponse , clazz );
16+ final String jsonFromResponse = EntityUtils .toString (response .getEntity ());
17+ final ObjectMapper mapper = new ObjectMapper ().configure (DeserializationFeature .FAIL_ON_UNKNOWN_PROPERTIES , false );
18+ return mapper .readValue (jsonFromResponse , clazz );
2419 }
2520
2621}
You can’t perform that action at this time.
0 commit comments