use of com.thebluealliance.androidclient.models.RankingResponseObject in project the-blue-alliance-android by the-blue-alliance.
the class RankingsResponseDeserializer method deserialize.
@Override
public RankingResponseObject deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
JsonObject rankingsObject = json.getAsJsonObject();
RankingResponseObject rankingResponse = new RankingResponseObject();
List<IRankingItem> teamRanks = new ArrayList<>();
List<IRankingSortOrder> sortOrders;
List<IRankingSortOrder> extraStats;
if (!isNull(rankingsObject.get("rankings"))) {
JsonArray rankJson = rankingsObject.get("rankings").getAsJsonArray();
for (int i = 0; i < rankJson.size(); i++) {
teamRanks.add(context.deserialize(rankJson.get(i), RankingItem.class));
}
}
if (!isNull(rankingsObject.get("sort_order_info"))) {
JsonArray sortOrderJson = rankingsObject.get("sort_order_info").getAsJsonArray();
sortOrders = context.deserialize(sortOrderJson, new TypeToken<List<RankingSortOrder>>() {
}.getType());
} else {
sortOrders = new ArrayList<>();
}
if (!isNull(rankingsObject.get("extra_stats_info"))) {
JsonArray extraStatsJson = rankingsObject.get("extra_stats_info").getAsJsonArray();
extraStats = context.deserialize(extraStatsJson, new TypeToken<List<RankingSortOrder>>() {
}.getType());
} else {
extraStats = new ArrayList<>();
}
rankingResponse.setRankings(teamRanks);
rankingResponse.setSortOrderInfo(sortOrders);
rankingResponse.setExtraStatsInfo(extraStats);
return rankingResponse;
}
Aggregations