Search in sources :

Example 1 with RankingResponseObject

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;
}
Also used : IRankingItem(com.thebluealliance.api.model.IRankingItem) RankingItem(com.thebluealliance.androidclient.models.RankingItem) IRankingSortOrder(com.thebluealliance.api.model.IRankingSortOrder) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) RankingResponseObject(com.thebluealliance.androidclient.models.RankingResponseObject) JsonArray(com.google.gson.JsonArray) IRankingItem(com.thebluealliance.api.model.IRankingItem) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 RankingItem (com.thebluealliance.androidclient.models.RankingItem)1 RankingResponseObject (com.thebluealliance.androidclient.models.RankingResponseObject)1 IRankingItem (com.thebluealliance.api.model.IRankingItem)1 IRankingSortOrder (com.thebluealliance.api.model.IRankingSortOrder)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1