Example usage for com.google.gson JsonObject getAsJsonObject

List of usage examples for com.google.gson JsonObject getAsJsonObject

Introduction

In this page you can find the example usage for com.google.gson JsonObject getAsJsonObject.

Prototype

public JsonObject getAsJsonObject(String memberName) 

Source Link

Document

Convenience method to get the specified member as a JsonObject.

Usage

From source file:com.tmobile.TMobileParsing.java

protected static Balance extractBalance(JsonObject jsonBillingAccount) {
    Balance balance = new Balance();
    JsonObject jsonBalance = jsonBillingAccount.getAsJsonObject("balance");
    balance.setRawValue(Float.valueOf(jsonBalance.get("rawValue").toString()));
    balance.setRoundedValue(Integer.valueOf(jsonBalance.get("roundedValue").toString()));

    return balance;
}

From source file:com.tmobile.TMobileParsing.java

protected static List<Profile> parseProfiles(JsonObject jsonProfiles) {
    List<Profile> profiles = new ArrayList<>();

    Set<Map.Entry<String, JsonElement>> keys = jsonProfiles.entrySet();
    ArrayList<Map.Entry<String, JsonElement>> profileIds = new ArrayList<>(keys);

    for (int i = 0; i < profileIds.size(); i++) {
        String profileId = profileIds.get(i).getKey();
        JsonObject jsonProfile = jsonProfiles.get(profileId).getAsJsonObject();
        String roleName = jsonProfile.get("roleName").getAsString();

        Profile profile = new Profile();
        profile.setId(profileId);/*ww w . j  av  a  2s.  c  o m*/
        profile.setRoleName(roleName);

        //Process billing account
        BillingAccount billingAccount = extractBillingAccount(jsonProfile);
        profile.setBillingAccount(billingAccount);
        //End of billing account

        //Process balance
        JsonObject jsonBillingAccount = jsonProfile.getAsJsonObject("billingAccount");

        Balance balance = extractBalance(jsonBillingAccount);
        billingAccount.setBalance(balance); //Set it in the billing account
        //End of balance

        //Process subscriptions
        List<Subscription> subscriptions = parseSubscriptions(
                jsonBillingAccount.getAsJsonObject("subscriptions"));
        billingAccount.setSubscriptions(subscriptions);
        //End of subscriptions

        profiles.add(profile);
    }

    return profiles;
}

From source file:com.vmware.eucenablement.horizontoolset.av.api.impl.VolumeImpl.java

/**
 * get all writable volumes from volume manager
 *
 * @return all writable volumes//  w  w w .  j  a  v a 2 s.c  om
 */
public List<Writable> listWritables() {
    List<Writable> writableList = null;
    try {
        String result = volumeHelper.requestProcess(null, "cv_api/writables", HTTPMethod.GET);

        if (result.contains("datastores") && result.contains("writable_volumes")) {
            Gson gson = new Gson();
            JsonParser parser = new JsonParser();
            JsonObject jsonObject = parser.parse(result).getAsJsonObject();
            JsonObject datastores = jsonObject.getAsJsonObject("datastores");
            JsonArray jsonWritables = datastores.getAsJsonArray("writable_volumes");

            writableList = gson.fromJson(jsonWritables, new TypeToken<List<Writable>>() {
            }.getType());

        } else {
            LOG.warn(new Date().toString() + ": can not get app stacks, try latter");
        }
    } catch (Exception e) {
        LOG.error(new Date().toString() + ": can not get writables, try latter:" + e);
    }

    return writableList;
}

From source file:com.vmware.eucenablement.horizontoolset.av.api.impl.VolumeImpl.java

public Writable getWritable(long id) {
    Writable writableDetail = null;/*from w  w  w .  j  a v  a2 s  . co m*/
    try {
        String result = volumeHelper.requestProcess(null, "cv_api/writables/" + id, HTTPMethod.GET);

        if (result.contains("writable")) {
            Gson gson = new Gson();
            JsonParser parser = new JsonParser();
            JsonObject jsonObject = parser.parse(result).getAsJsonObject();
            JsonObject jsonWritable = jsonObject.getAsJsonObject("writable");
            writableDetail = gson.fromJson(jsonWritable, Writable.class);
        }

    } catch (Exception e) {
        LOG.error(new Date().toString() + ": can not get writable volume, try latter:" + e);
    }

    return writableDetail;
}

From source file:com.vmware.eucenablement.horizontoolset.av.api.impl.VolumeImpl.java

/**
 * get all available app stacks from volume manager
 *
 * @return all app stacks/*from ww w . j av a2s .c  om*/
 */
public List<AppStack> listAppStacks() {
    List<AppStack> appStackList = null;
    try {
        String result = volumeHelper.requestProcess(null, "cv_api/appstacks", HTTPMethod.GET);
        if (result.contains("currentappstacks") && result.contains("appstacks")) {
            Gson gson = new Gson();
            JsonParser parser = new JsonParser();
            JsonObject jsonObject = parser.parse(result).getAsJsonObject();
            JsonObject currentappstacks = jsonObject.getAsJsonObject("currentappstacks");
            JsonArray appstacks = currentappstacks.getAsJsonArray("appstacks");

            appStackList = gson.fromJson(appstacks, new TypeToken<List<AppStack>>() {
            }.getType());

        } else {
            LOG.warn(new Date().toString() + ": can not get app stacks, try latter");
        }

    } catch (Exception e) {
        LOG.error(new Date().toString() + ": can not get app stacks, try latter:" + e);
    }
    return appStackList;
}

From source file:com.vmware.eucenablement.horizontoolset.av.api.impl.VolumeImpl.java

public AppStack getAppStack(long id) {
    AppStack appStackDetail = null;// w w w. j  av a  2s.c o m
    try {
        String result = volumeHelper.requestProcess(null, "cv_api/appstacks/" + id, HTTPMethod.GET);
        if (result.contains("appstack")) {
            Gson gson = new Gson();
            JsonParser parser = new JsonParser();
            JsonObject jsonObject = parser.parse(result).getAsJsonObject();
            JsonObject appstack = jsonObject.getAsJsonObject("appstack");
            appStackDetail = gson.fromJson(appstack, AppStack.class);
        }
    } catch (Exception e) {
        LOG.error(new Date().toString() + ": can not get app stacks, try latter:" + e);
    }
    return appStackDetail;
}

From source file:com.vmware.eucenablement.horizontoolset.av.api.impl.VolumeImpl.java

/**
 * get the online entites currently//from  w w w  .  j  ava 2 s .  co m
 *
 * @return list, online entities
 */
public List<OnlineEntity> listOnlineEntities() {
    List<OnlineEntity> onlineEntityList = null;
    try {
        String result = volumeHelper.requestProcess(null, "cv_api/online_entities", HTTPMethod.GET);
        if (result.contains("online") && result.contains("records")) {
            Gson gson = new Gson();
            JsonParser parser = new JsonParser();
            JsonObject jsonObject = parser.parse(result).getAsJsonObject();
            JsonObject onlines = jsonObject.getAsJsonObject("online");
            JsonArray records = onlines.getAsJsonArray("records");
            onlineEntityList = gson.fromJson(records, new TypeToken<List<OnlineEntity>>() {
            }.getType());
        }

    } catch (Exception e) {
        LOG.error(new Date().toString() + ": can not get online entity: " + e);
    }
    return onlineEntityList;
}

From source file:com.wallellen.wechat.mp.util.json.WxMpMaterialNewsBatchGetGsonItemAdapter.java

License:Open Source License

public WxMpMaterialNewsBatchGetResult.WxMaterialNewsBatchGetNewsItem deserialize(JsonElement jsonElement,
        Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
    WxMpMaterialNewsBatchGetResult.WxMaterialNewsBatchGetNewsItem wxMaterialNewsBatchGetNewsItem = new WxMpMaterialNewsBatchGetResult.WxMaterialNewsBatchGetNewsItem();
    JsonObject json = jsonElement.getAsJsonObject();
    if (json.get("media_id") != null && !json.get("media_id").isJsonNull()) {
        wxMaterialNewsBatchGetNewsItem.setMediaId(GsonHelper.getAsString(json.get("media_id")));
    }//www . ja v a  2  s. c  o m
    if (json.get("update_time") != null && !json.get("update_time").isJsonNull()) {
        wxMaterialNewsBatchGetNewsItem
                .setUpdateTime(new Date(1000 * GsonHelper.getAsLong(json.get("update_time"))));
    }
    if (json.get("content") != null && !json.get("content").isJsonNull()) {
        JsonObject newsItem = json.getAsJsonObject("content");
        wxMaterialNewsBatchGetNewsItem
                .setContent(WxMpGsonBuilder.create().fromJson(newsItem, WxMpMaterialNews.class));
    }
    return wxMaterialNewsBatchGetNewsItem;
}

From source file:com.willwinder.universalgcodesender.TinyGUtils.java

License:Open Source License

public static boolean isTinyGVersion(JsonObject response) {
    if (response.has(FIELD_RESPONSE)) {
        JsonObject jo = response.getAsJsonObject(FIELD_RESPONSE);
        if (jo.has(FIELD_FIRMWARE_VERSION)) {
            return true;
        }//from  w ww . ja va 2 s.c  o  m
    }
    return false;
}

From source file:com.willwinder.universalgcodesender.TinyGUtils.java

License:Open Source License

public static String getVersion(JsonObject response) {
    if (response.has(FIELD_RESPONSE)) {
        JsonObject jo = response.getAsJsonObject(FIELD_RESPONSE);
        if (jo.has(FIELD_FIRMWARE_VERSION)) {
            return jo.get(FIELD_FIRMWARE_VERSION).getAsString();
        }//from  w w  w .  j a  va  2s.  c  om
    }
    return "";
}