Example usage for com.google.gson JsonElement getAsInt

List of usage examples for com.google.gson JsonElement getAsInt

Introduction

In this page you can find the example usage for com.google.gson JsonElement getAsInt.

Prototype

public int getAsInt() 

Source Link

Document

convenience method to get this element as a primitive integer value.

Usage

From source file:uk.codingbadgers.SurvivalPlus.serialization.ItemStackSerializer.java

License:Open Source License

private List<Color> colorFromJson(JsonArray colors) {
    List<Color> array = new ArrayList<Color>();

    for (JsonElement color : colors) {
        array.add(Color.fromRGB(color.getAsInt()));
    }/*ww  w  .j av  a 2s.c  om*/

    return array;
}

From source file:wvw.mobibench.devserv.server.serial.EnumDeserializer.java

License:Apache License

@SuppressWarnings({ "unchecked" })
public Enum deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {

    return (Enum) EnumSet.allOf((Class) typeOfT).toArray()[json.getAsInt()];
}

From source file:xyz.deltaevo.jvultr.api.JVultrPlan.java

License:Open Source License

/**
 * DON'T USE THIS CONSTRUCTOR !// www. j  a  v  a 2s.c  o  m
 * @param value the JsonObject representing this object
 */
public JVultrPlan(JsonObject value) {
    this.id = value.get("VPSPLANID").getAsInt();
    this.name = value.get("name").getAsString();
    this.cpus = value.get("vcpu_count").getAsInt();
    this.ram = value.get("ram").getAsInt();
    this.disk = value.get("disk").getAsInt();
    this.bandwidth = value.get("bandwidth").getAsFloat();
    this.pricePerMonth = value.get("price_per_month").getAsFloat();
    this.windows = value.get("windows").getAsBoolean();
    this.type = Type.valueOf(value.get("plan_type").getAsString());
    if (value.has("available_locations")) {
        JsonArray array = value.get("available_locations").getAsJsonArray();
        availableRegions = new JVultrRegion[array.size()];
        int i = 0;
        for (JsonElement element : array) {
            availableRegions[i] = JVultrCache.getCachedRegion(element.getAsInt());
            i++;
        }
    } else {
        availableRegions = new JVultrRegion[0];
    }
}

From source file:xyz.deltaevo.jvultr.JVultrAPI.java

License:Open Source License

public static List<JVultrPlan> getPlansFor(int regionId) throws JVultrException {
    JsonElement response = new JsonParser()
            .parse(get(JVultrAPI.ENDPOINT + "v1/regions/availability?DCID=" + regionId, null));
    if (response.isJsonArray()) {
        List<JVultrPlan> availablePlans = new ArrayList<>();
        for (JsonElement element : response.getAsJsonArray()) {
            availablePlans.add(JVultrCache.getCachedPlan(element.getAsInt()));
        }/*from  w  ww.  j  a v  a2 s.com*/
        return availablePlans;
    }
    return new ArrayList<>();
}

From source file:xyz.deltaevo.jvultr.JVultrClient.java

License:Open Source License

public List<JVultrPlan> getUpgradePlanList(int serverId) throws JVultrException {
    JsonElement response = new JsonParser()
            .parse(JVultrAPI.get(JVultrAPI.ENDPOINT + "v1/server/upgrade_plan_list?SUBID=" + serverId, apiKey));
    if (response.isJsonArray()) {
        List<JVultrPlan> servers = new ArrayList<>();
        for (JsonElement element : response.getAsJsonArray()) {
            servers.add(JVultrCache.getCachedPlan(element.getAsInt()));
        }//from   w w w .  java 2 s . c o m
        return servers;
    }
    return new ArrayList<>();
}