List of usage examples for com.google.gson.reflect TypeToken TypeToken
@SuppressWarnings("unchecked") protected TypeToken()
From source file:api.Ulti.java
License:Open Source License
/** * Queries for the team by the teams ID. A maximum of 40 team IDs can be provided. * * @param teamIds the IDs of the teams to lookup * @return a {@link java.util.Map} containing each a {@link dto.team.Team} object corresponding to each * team ID provided./*from w ww . j a va 2 s . c om*/ */ public Map<String, Team> getTeamById(String... teamIds) { if (!passLengthConstraint(teamIds, 10)) { throw new UltiException(UltiException.Type.INVALID_PARAMETERS); } Reader json = api.query(versions.get("team") + "/team/" + prepare(teamIds, false)); Type type = new TypeToken<Map<String, Team>>() { }.getType(); return gson.fromJson(json, type); }
From source file:api.Ulti.java
License:Open Source License
/** * Queries for the leagues of each summoner ID provided. A maximum of 10 summoner IDs can be provided. * * @param summonerIds the IDs of the summoners to lookup * @return a {@link java.util.Map} containing a {@link java.util.List} of each {@link dto.league.League} * the summoner is a part of/*from w w w. j a va 2s . co m*/ */ public Map<String, List<League>> getLeagueBySummonerId(Long... summonerIds) { if (!passLengthConstraint(summonerIds, 10)) { throw new UltiException(UltiException.Type.INVALID_PARAMETERS); } Reader json = api.query(versions.get("league") + "/league/by-summoner/" + prepare(summonerIds)); Type type = new TypeToken<Map<String, List<League>>>() { }.getType(); return gson.fromJson(json, type); }
From source file:api.Ulti.java
License:Open Source License
/** * Queries for the league entries of the provided summoner IDs. A maximum of 10 summoner IDs can be provided. * * @param summonerIds the IDs of the summoners to lookup * @return a {@link java.util.Map} of each {@link dto.league.League} the summoner is a part of, only containing * a {@link dto.league.LeagueEntry} for the summoner *//*from w w w . j a v a 2 s . c o m*/ public Map<String, List<League>> getLeagueEntryBySummonerId(Long... summonerIds) { if (!passLengthConstraint(summonerIds, 10)) { throw new UltiException(UltiException.Type.INVALID_PARAMETERS); } Reader json = api.query(versions.get("league") + "/league/by-summoner/" + prepare(summonerIds) + "/entry"); Type type = new TypeToken<Map<String, List<League>>>() { }.getType(); return gson.fromJson(json, type); }
From source file:api.Ulti.java
License:Open Source License
/** * Queries for leagues of each team ID provided. A maximum of 10 team IDs can be provided. * * @param teamIds the IDs of the teams to lookup * @return a {@link java.util.Map} containing a {@link java.util.List} of each {@link dto.league.League} * the team is a part of (3v3 and 5v5 leagues). The {@link dto.league.League} object contains a * {@link dto.league.LeagueEntry} for each summoner in the respective league. *//* w w w. j a va 2 s . co m*/ public Map<String, List<League>> getTeamLeagueById(String... teamIds) { if (!passLengthConstraint(teamIds, 10)) { throw new UltiException(UltiException.Type.INVALID_PARAMETERS); } Reader json = api.query(versions.get("league") + "/league/by-team/" + prepare(teamIds, false)); Type type = new TypeToken<Map<String, List<League>>>() { }.getType(); return gson.fromJson(json, type); }
From source file:api.Ulti.java
License:Open Source License
/** * Queries for the league entries of the team IDs. A maximum of 10 team IDs can be provided. * * @param teamIds the IDs of the teams to lookup * @return a {@link java.util.Map} containing a {@link java.util.List} of each {@link dto.league.League} * the team is a part of (3v3 and 5v5 leagues). The {@link dto.league.League} object only contains * a {@link dto.league.LeagueEntry} for the given team IDs. *///from w w w . j a v a 2s .c o m public Map<String, List<League>> getTeamLeagueEntryById(String... teamIds) { if (!passLengthConstraint(teamIds, 10)) { throw new UltiException(UltiException.Type.INVALID_PARAMETERS); } Reader json = api.query(versions.get("league") + "/league/by-team/" + prepare(teamIds, false) + "/entry"); Type type = new TypeToken<Map<String, List<League>>>() { }.getType(); return gson.fromJson(json, type); }
From source file:api.Ulti.java
License:Open Source License
/** * Queries for the status of all LOL servers. * * @return a {@link java.util.List} of {@link dto.status.Shard} objects reflecting the server status *///from w ww. jav a 2 s . co m public List<Shard> getServerStatus() { Reader json = api.statusQuery("shards"); Type type = new TypeToken<List<Shard>>() { }.getType(); return gson.fromJson(json, type); }
From source file:api.Ulti.java
License:Open Source License
/** * Queries the static api for all versions of the data * * @return a {@link java.util.List} of {@link java.lang.String} containing each version of the static data backend *///from www.j a v a 2s . co m public List<String> getStaticVersions() { Reader json = api.staticQuery(versions.get("static-data") + "/versions"); Type type = new TypeToken<List<String>>() { }.getType(); return gson.fromJson(json, type); }
From source file:App.App.java
private static void showTeam() { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Table 'Teams' consist of 5 columns: name, city, stadium, cups and foundation"); System.out.println("For selection print column name like name=Arsenal to select information about club"); System.out.println(//from www . java 2 s. c o m "For multiply selection write column name and <,> or = and value, after thar write 'and' and another columnt name and expression"); System.out.println("Example, 'city=London and cups>3 and foundation>1900'"); System.out.println("For exit write exit"); try { String temp = br.readLine(); JSONObject json = new JSONObject(); String[] parts = temp.split("and"); for (String str : parts) { String[] tmp = str.split("<|>|="); tmp[0] = tmp[0].trim(); tmp[1] = tmp[1].trim(); for (int i = 0; i < str.length(); ++i) { switch (str.charAt(i)) { case '=': tmp[0] += '='; break; case '>': tmp[0] += '>'; break; case '<': tmp[0] += '<'; break; } } json.put(tmp[0], tmp[1]); } String jsonString = json.toString(); Client client = Client.create(); WebResource webResource = client.resource(URL); webResource = webResource.queryParam("name", URLEncoder.encode(jsonString, "UTF-8")); ClientResponse response = webResource.accept(MediaType.APPLICATION_JSON + ";charset=utf-8") .header("Login", "user").header("Pass", "user").get(ClientResponse.class); if (response.getStatus() != ClientResponse.Status.OK.getStatusCode()) { throw new IllegalStateException(response.getEntity(String.class)); } String str = response.getEntity(String.class); List<Team> teams = new Gson().fromJson(str, new TypeToken<List<Team>>() { }.getType()); for (Team team : teams) { System.out.println( "name: " + team.getName() + ", city: " + team.getCity() + ", stadium: " + team.getStadium() + ", year of foudation: " + team.getYear() + ", total cups: " + team.getCups()); } System.out.println("Total teams: " + teams.size()); } catch (Exception e) { System.out.println(e.getMessage()); } }
From source file:app.witness.com.myapplication.category_one.DemoActivity.java
License:Open Source License
@OnClick(R.id.btnMakeCoffee) public void onClick() { Poetry poetry = new Poetry("life is so dili"); Poetry poetry2 = new Poetry("what is life"); Poetry poetry3 = new Poetry("just look"); Poetry poetry4 = new Poetry("that's good"); Map<String, Poetry> datas = new HashMap<>(); datas.put("poetry", poetry); datas.put("poetry2", poetry2); datas.put("poetry3", poetry3); datas.put("poetry4", poetry4); Gson gson = new Gson(); String result = gson.toJson(datas); tvCoffee.append(result);//from w w w. j a va 2s . c om tvCoffee.append("\n"); Map<String, Poetry> reverse = gson.fromJson(result, new TypeToken<Map<String, Poetry>>() { }.getType()); tvCoffee.append(reverse.toString()); tvCoffee.append("\n"); }
From source file:apprenda.clientservices.tasks.ApprendaDeployTask.java
License:Apache License
private Collection<Application> getAppList(HttpClient client, BuildLogger buildLogger, String tenant) { buildLogger.addBuildLogEntry("Grabbing Existing Applications for " + tenant + "."); HttpGet httpGet = new HttpGet(platformRoot + Constants.GET_APPLICATIONS_URL); httpGet.addHeader("Content-Type", "application/json"); httpGet.addHeader("ApprendaSessionToken", apprendaSession); Response result = executeMessage(client, httpGet, buildLogger); Collection<Application> applications = getObjectFromJson(result.ResponseBody, new TypeToken<Collection<Application>>() { });//from w w w. j a v a2s. co m return applications; }