List of usage examples for com.google.gson.reflect TypeToken TypeToken
@SuppressWarnings("unchecked") protected TypeToken()
From source file:br.ufjf.parsifal.core.ParsifalClient.java
License:Open Source License
@Override public List<SelectionCriteria> getReviewSelectionCriterias(String reviewId) throws ParsifalException { String url = "/selection_criterias?review=" + reviewId; HttpURLConnection response = request(url, "GET", 200, "application/json"); String content = parseResponse(response); SearchResult<SelectionCriteria> results = new Gson().fromJson(content, new TypeToken<SearchResult<SelectionCriteria>>() { }.getType());/*from w ww. j av a2 s. co m*/ return results.getResults(); }
From source file:br.ufjf.parsifal.core.ParsifalClient.java
License:Open Source License
@Override public List<Source> getSources() throws ParsifalException { String url = "/sources"; HttpURLConnection response = request(url, "GET", 200, "application/json"); String content = parseResponse(response); SearchResult<Source> results = new Gson().fromJson(content, new TypeToken<SearchResult<Source>>() { }.getType());/*from w ww. ja va 2 s. co m*/ return results.getResults(); }
From source file:br.ufjf.pgcc.plscience.social.apli.client.DblpClient.java
public static DblpAuthor getAuthor(String authorName, String host) { try {/*from w w w . j ava2s. c om*/ String authorPath = "/dblp/author/"; String publications = "/publications/"; String coauthors = "/coauthors"; String protocol = "http://"; String port = ":8080"; authorName = authorName.replaceAll(" ", "%20"); Client c = Client.create(); WebResource wr = c.resource(protocol + host + port + authorPath + authorName); String json = wr.get(String.class); Gson gson = new Gson(); DblpAuthor author = gson.fromJson(json, new TypeToken<DblpAuthor>() { }.getType()); wr = c.resource(protocol + host + port + authorPath + authorName + publications); json = wr.get(String.class); wr = c.resource(protocol + host + port + authorPath + authorName + coauthors); json = wr.get(String.class); Type listType = new TypeToken<List<Coauthor>>() { }.getType(); List<Coauthor> coauths = gson.fromJson(json, listType); author.setCoauthors(coauths); return author; } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:br.ufjf.pgcc.plscience.social.apli.client.ScholarClient.java
public static ScholarAuthor getAuthor(String authorName, String host) { try {/*from w w w .j a v a 2 s .c o m*/ String authorPath = "/scholar/author/"; String publications = "/publications/"; String protocol = "http://"; String port = ":8080"; authorName = authorName.replaceAll(" ", "%20"); Client c = Client.create(); WebResource wr = c.resource(protocol + host + port + authorPath + authorName); String json = wr.get(String.class); Gson gson = new Gson(); ScholarAuthor author = gson.fromJson(json, new TypeToken<ScholarAuthor>() { }.getType()); wr = c.resource(protocol + host + port + authorPath + authorName + publications); json = wr.get(String.class); Type listType = new TypeToken<List<Publication>>() { }.getType(); List<Publication> pubs = gson.fromJson(json, listType); author.setPublications(pubs); return author; } catch (JsonSyntaxException | UniformInterfaceException e) { return null; } }
From source file:br.ufjf.pgcc.plscience.social.apli.client.ScholarClient.java
public static Publication getFilledPublication(String authorName, String publicationId, String host) { try {/*ww w . j av a2 s. co m*/ String authorPath = "/scholar/author/"; String publications = "/publications/"; String protocol = "http://"; String port = ":8080"; authorName = authorName.replaceAll(" ", "%20"); Client c = Client.create(); WebResource wr = c .resource(protocol + host + port + authorPath + authorName + publications + publicationId); String json = wr.get(String.class); Gson gson = new Gson(); return gson.fromJson(json, new TypeToken<Publication>() { }.getType()); } catch (JsonSyntaxException | UniformInterfaceException e) { return null; } }
From source file:br.upf.contatos.rest.integracao.webservicerestconect.MediadorRest.java
public List<Contato> getContatos() { List<Contato> listaContatos = new ArrayList<>(); Gson jsonContatos = new Gson(); try {/*from w ww .j av a 2 s. c o m*/ HttpURLConnection con = (HttpURLConnection) (new URL("http://localhost:8080/contatos/rest/contato")) .openConnection(); con.setRequestMethod("GET"); con.setRequestProperty("Accept", "application/json"); if (con.getResponseCode() != 200) { return null; } else { BufferedReader br = new BufferedReader(new InputStreamReader((con.getInputStream()))); StringBuilder resultado = new StringBuilder(); String line; while ((line = br.readLine()) != null) { resultado.append(line); } System.out.println(resultado.toString()); Type collectionType = new TypeToken<List<Contato>>() { }.getType(); listaContatos = jsonContatos.fromJson(resultado.toString(), collectionType); } } catch (IOException | JsonSyntaxException e) { } return listaContatos; }
From source file:BusinessLogic.Controller.RestController.java
public List<Plan> getPlans() throws Exception { StringBuilder responseS = new StringBuilder(); try {//from ww w . j av a 2 s.co m DefaultHttpClient httpClient = new DefaultHttpClient(); HttpGet getRequest = new HttpGet("http://localhost:8080/JoyCenter/resources/plans"); getRequest.addHeader("accept", "application/json"); HttpResponse response = httpClient.execute(getRequest); if (response.getStatusLine().getStatusCode() != 200) { throw new RuntimeException( "Failed : HTTP error code : " + response.getStatusLine().getStatusCode()); } BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent()))); String output; System.out.println("Output from Server .... \n"); while ((output = br.readLine()) != null) { responseS.append(output); } httpClient.getConnectionManager().shutdown(); } catch (IOException e) { } Gson gson = new Gson(); List<Plan> planes = gson.fromJson(responseS.toString(), new TypeToken<List<Plan>>() { }.getType()); return planes; }
From source file:BusinessLogic.Controller.RestController.java
public List<Hotel> getHotels() throws Exception { StringBuilder responseS = new StringBuilder(); try {/*from w ww .ja v a 2 s . c o m*/ DefaultHttpClient httpClient = new DefaultHttpClient(); HttpGet getRequest = new HttpGet("http://192.168.162.121/Hoex/hoexAPI/hoteles"); getRequest.addHeader("accept", "application/json"); HttpResponse response = httpClient.execute(getRequest); if (response.getStatusLine().getStatusCode() != 200) { throw new RuntimeException( "Failed : HTTP error code : " + response.getStatusLine().getStatusCode()); } BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent()))); String output; System.out.println("Output from Server .... \n"); while ((output = br.readLine()) != null) { responseS.append(output); } httpClient.getConnectionManager().shutdown(); } catch (IOException e) { } Gson gson = new Gson(); List<Hotel> hoteles = gson.fromJson(responseS.toString(), new TypeToken<List<Hotel>>() { }.getType()); return hoteles; }
From source file:BusinessLogic.Controller.RestController.java
public List<Viaje> getViajes() throws Exception { StringBuilder responseS = new StringBuilder(); try {// ww w . j av a 2s . c om DefaultHttpClient httpClient = new DefaultHttpClient(); HttpGet getRequest = new HttpGet("http://192.168.162.167/Terminal/resources/viajes/"); getRequest.addHeader("accept", "application/json"); HttpResponse response = httpClient.execute(getRequest); if (response.getStatusLine().getStatusCode() != 200) { throw new RuntimeException( "Failed : HTTP error code : " + response.getStatusLine().getStatusCode()); } BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent()))); String output; System.out.println("Output from Server .... \n"); while ((output = br.readLine()) != null) { responseS.append(output); } httpClient.getConnectionManager().shutdown(); } catch (IOException e) { } Gson gson = new Gson(); List<Viaje> viajes = gson.fromJson(responseS.toString(), new TypeToken<List<Viaje>>() { }.getType()); return viajes; }
From source file:by.klnvch.link5dots.db.Converters.java
License:Open Source License
@TypeConverter public static ArrayList<Dot> stringToString(String dots) { return dots == null ? null : new Gson().fromJson(dots, new TypeToken<ArrayList<Dot>>() { }.getType());// w w w . j ava 2 s . c o m }