thelittlewozniak

Untitled

Dec 30th, 2018
384
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.93 KB | None | 0 0
  1. package model.dao;
  2.  
  3. import com.fasterxml.jackson.core.type.TypeReference;
  4. import com.fasterxml.jackson.databind.ObjectMapper;
  5. import com.sun.jersey.api.client.Client;
  6. import com.sun.jersey.api.client.WebResource;
  7. import model.pojo.User;
  8.  
  9. import javax.ws.rs.core.MediaType;
  10. import java.io.IOException;
  11. import java.util.ArrayList;
  12. import java.util.List;
  13.  
  14. public class Test {
  15.     public static void main(String[] args){
  16.         Client client= Client.create();
  17.         WebResource webResource=client.resource("http://localhost:9090/Facebook_API_war_exploded/rest/");
  18.         String response = webResource.path("User/getAll").accept(MediaType.APPLICATION_JSON).get(String.class);
  19.         ObjectMapper mapper =new ObjectMapper();
  20.         List<User> users=new ArrayList<>();
  21.         try {
  22.             users=mapper.readValue(response, new TypeReference<List<User>>(){});
  23.         } catch (IOException e) {
  24.             e.printStackTrace();
  25.         }
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment