All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.robrua.orianna.api.dto.ChampionSpellDeserializer Maven / Gradle / Ivy

There is a newer version: 2.4.5
Show newest version
package com.robrua.orianna.api.dto;

import java.lang.reflect.Type;
import java.util.List;

import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.reflect.TypeToken;
import com.robrua.orianna.type.dto.staticdata.ChampionSpell;
import com.robrua.orianna.type.dto.staticdata.Image;
import com.robrua.orianna.type.dto.staticdata.LevelTip;
import com.robrua.orianna.type.dto.staticdata.SpellVars;

public class ChampionSpellDeserializer extends DtoDeserializer {
    @SuppressWarnings("unchecked")
    @Override
    public ChampionSpell deserialize(final JsonElement json, final Type type, final JsonDeserializationContext context) throws JsonParseException {
        final JsonObject obj = json.getAsJsonObject();
        final ChampionSpell spell = new ChampionSpell();
        Type t;

        t = new TypeToken>() {}.getType();
        spell.setAltimages((List)GSON.fromJson(obj.get("altimages"), t));

        t = new TypeToken>() {}.getType();
        spell.setCooldown((List)GSON.fromJson(obj.get("cooldown"), t));

        spell.setCooldownBurn(GSON.fromJson(obj.get("cooldownBurn"), String.class));
        spell.setCostBurn(GSON.fromJson(obj.get("costBurn"), String.class));
        spell.setCostType(GSON.fromJson(obj.get("costType"), String.class));
        spell.setDescription(GSON.fromJson(obj.get("description"), String.class));
        spell.setKey(GSON.fromJson(obj.get("key"), String.class));
        spell.setName(GSON.fromJson(obj.get("name"), String.class));
        spell.setRangeBurn(GSON.fromJson(obj.get("rangeBurn"), String.class));
        spell.setResource(GSON.fromJson(obj.get("resource"), String.class));
        spell.setSanitizedDescription(GSON.fromJson(obj.get("sanitizedDescription"), String.class));
        spell.setSanitizedTooltip(GSON.fromJson(obj.get("sanitizedTooltip"), String.class));
        spell.setTooltip(GSON.fromJson(obj.get("tooltip"), String.class));

        t = new TypeToken>() {}.getType();
        spell.setCost((List)GSON.fromJson(obj.get("cost"), t));

        try {
            spell.setRange((List)GSON.fromJson(obj.get("range"), t));
        }
        catch(final JsonParseException e) {
            spell.setRange(null);
        }

        t = new TypeToken>>() {}.getType();
        spell.setEffect((List>)GSON.fromJson(obj.get("effect"), t));

        t = new TypeToken>() {}.getType();
        spell.setEffectBurn((List)GSON.fromJson(obj.get("effectBurn"), t));

        spell.setImage(GSON.fromJson(obj.get("image"), Image.class));
        spell.setLeveltip(GSON.fromJson(obj.get("leveltip"), LevelTip.class));
        spell.setMaxrank(GSON.fromJson(obj.get("maxrank"), Integer.class));

        t = new TypeToken>() {}.getType();
        spell.setVars((List)GSON.fromJson(obj.get("vars"), t));

        return spell;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy