Merge pull request #6722 from amit2103/BAEL-14090
[BAEL-14090] - Moved code for Testing REST API article
This commit is contained in:
commit
a821cd553d
|
@ -0,0 +1,21 @@
|
|||
package com.baeldung.rest;
|
||||
|
||||
public class GitHubUser {
|
||||
|
||||
private String login;
|
||||
|
||||
public GitHubUser() {
|
||||
super();
|
||||
}
|
||||
|
||||
// API
|
||||
|
||||
public String getLogin() {
|
||||
return login;
|
||||
}
|
||||
|
||||
public void setLogin(final String login) {
|
||||
this.login = login;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.rest;
|
||||
package com.baeldung.rest;
|
||||
|
||||
import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
|
@ -0,0 +1,21 @@
|
|||
package com.baeldung.rest;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
public class RetrieveUtil {
|
||||
|
||||
// API
|
||||
|
||||
public static <T> T retrieveResourceFromResponse(final HttpResponse response, final Class<T> clazz) throws IOException {
|
||||
final String jsonFromResponse = EntityUtils.toString(response.getEntity());
|
||||
final ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
return mapper.readValue(jsonFromResponse, clazz);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue