Example usage for com.google.gson JsonObject getAsJsonArray

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

Introduction

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

Prototype

public JsonArray getAsJsonArray(String memberName) 

Source Link

Document

Convenience method to get the specified member as a JsonArray.

Usage

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

/**
 * Expand a writable volume//from w  w w.  j av  a  2 s  .  c om
 *
 * @param ID for writable volume
 *
 * @return if success, ExcuteResult.resultFlag is RES_SUCCESS. if failure,
 *         this field is other values.
 */
public ExcuteResult expandWritableVolume(Long writeVolume_id, Long volumeSize) {

    ExcuteResult resultExcuted = new ExcuteResult();
    String msgDescription = "";

    Map<String, String> map_expandParameters = new HashMap<String, String>();
    map_expandParameters.put("size_mb", volumeSize.toString());
    map_expandParameters.put("volumes[]", writeVolume_id.toString());

    try {
        String result = volumeHelper.requestProcess(map_expandParameters, "cv_api/writables/grow",
                HTTPMethod.POST);
        JsonParser parser = new JsonParser();
        JsonObject jsonObject = parser.parse(result).getAsJsonObject();
        JsonArray jsonSuccesses = jsonObject.getAsJsonArray("successes");
        JsonArray jsonWarnings = jsonObject.getAsJsonArray("warnings");
        JsonArray jsonErrors = jsonObject.getAsJsonArray("errors");

        if ((jsonSuccesses != null) && (jsonSuccesses.size() > 0)) {
            resultExcuted.resultFlag = ExcuteResult.RES_SUCCESS;
            msgDescription += jsonSuccesses.getAsString();
        } else if ((jsonWarnings != null) && (jsonWarnings.size() > 0)) {
            resultExcuted.resultFlag = ExcuteResult.RES_GENERAL_FAILURE;
            msgDescription += jsonWarnings.getAsString();

        } else if ((jsonErrors != null) && (jsonErrors.size() > 0)) {
            resultExcuted.resultFlag = ExcuteResult.RES_GENERAL_FAILURE;
            msgDescription += jsonErrors.getAsString();
        } else {
            LOG.warn(new Date().toString() + ": can not expand writable volumes");
            resultExcuted.resultFlag = ExcuteResult.RES_GENERAL_FAILURE;
            msgDescription += "Can not expand writable volumes.";
        }

    } catch (Exception e) {
        LOG.error(new Date().toString() + ": can not unassign app stack to users: " + e);
        resultExcuted.resultFlag = ExcuteResult.RES_GENERAL_FAILURE;
        msgDescription = "Can not expand writable volumes. Exceptions: " + e;
    }

    resultExcuted.message = msgDescription;

    return resultExcuted;
}

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

License:Open Source License

public WxMpMassNews deserialize(JsonElement jsonElement, Type type,
        JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
    WxMpMassNews wxMpMassNews = new WxMpMassNews();
    JsonObject json = jsonElement.getAsJsonObject();
    if (json.get("media_id") != null && !json.get("media_id").isJsonNull()) {
        JsonArray articles = json.getAsJsonArray("articles");
        for (JsonElement article1 : articles) {
            JsonObject articleInfo = article1.getAsJsonObject();
            WxMpMassNews.WxMpMassNewsArticle article = WxMpGsonBuilder.create().fromJson(articleInfo,
                    WxMpMassNews.WxMpMassNewsArticle.class);
            wxMpMassNews.addArticle(article);
        }// www .j  ava2s.  com
    }
    return wxMpMassNews;
}

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

License:Open Source License

public WxMpMaterialFileBatchGetResult deserialize(JsonElement jsonElement, Type type,
        JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
    WxMpMaterialFileBatchGetResult wxMpMaterialFileBatchGetResult = new WxMpMaterialFileBatchGetResult();
    JsonObject json = jsonElement.getAsJsonObject();
    if (json.get("total_count") != null && !json.get("total_count").isJsonNull()) {
        wxMpMaterialFileBatchGetResult.setTotalCount(GsonHelper.getAsInteger(json.get("total_count")));
    }/*from  ww w.  j  a va  2s  . co  m*/
    if (json.get("item_count") != null && !json.get("item_count").isJsonNull()) {
        wxMpMaterialFileBatchGetResult.setItemCount(GsonHelper.getAsInteger(json.get("item_count")));
    }
    if (json.get("item") != null && !json.get("item").isJsonNull()) {
        JsonArray item = json.getAsJsonArray("item");
        List<WxMpMaterialFileBatchGetResult.WxMaterialFileBatchGetNewsItem> items = new ArrayList<>();
        for (JsonElement anItem : item) {
            JsonObject articleInfo = anItem.getAsJsonObject();
            items.add(WxMpGsonBuilder.create().fromJson(articleInfo,
                    WxMpMaterialFileBatchGetResult.WxMaterialFileBatchGetNewsItem.class));
        }
        wxMpMaterialFileBatchGetResult.setItems(items);
    }
    return wxMpMaterialFileBatchGetResult;
}

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

License:Open Source License

public WxMpMaterialNewsBatchGetResult deserialize(JsonElement jsonElement, Type type,
        JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
    WxMpMaterialNewsBatchGetResult wxMpMaterialNewsBatchGetResult = new WxMpMaterialNewsBatchGetResult();
    JsonObject json = jsonElement.getAsJsonObject();
    if (json.get("total_count") != null && !json.get("total_count").isJsonNull()) {
        wxMpMaterialNewsBatchGetResult.setTotalCount(GsonHelper.getAsInteger(json.get("total_count")));
    }//from w  w  w . ja v a 2s  .co m
    if (json.get("item_count") != null && !json.get("item_count").isJsonNull()) {
        wxMpMaterialNewsBatchGetResult.setItemCount(GsonHelper.getAsInteger(json.get("item_count")));
    }
    if (json.get("item") != null && !json.get("item").isJsonNull()) {
        JsonArray item = json.getAsJsonArray("item");
        List<WxMpMaterialNewsBatchGetResult.WxMaterialNewsBatchGetNewsItem> items = new ArrayList<>();
        for (JsonElement anItem : item) {
            JsonObject articleInfo = anItem.getAsJsonObject();
            items.add(WxMpGsonBuilder.create().fromJson(articleInfo,
                    WxMpMaterialNewsBatchGetResult.WxMaterialNewsBatchGetNewsItem.class));
        }
        wxMpMaterialNewsBatchGetResult.setItems(items);
    }
    return wxMpMaterialNewsBatchGetResult;
}

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

License:Open Source License

public WxMpMaterialNews deserialize(JsonElement jsonElement, Type type,
        JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
    WxMpMaterialNews wxMpMaterialNews = new WxMpMaterialNews();
    JsonObject json = jsonElement.getAsJsonObject();
    if (json.get("news_item") != null && !json.get("news_item").isJsonNull()) {
        JsonArray articles = json.getAsJsonArray("news_item");
        for (JsonElement article1 : articles) {
            JsonObject articleInfo = article1.getAsJsonObject();
            WxMpMaterialNews.WxMpMaterialNewsArticle article = WxMpGsonBuilder.create().fromJson(articleInfo,
                    WxMpMaterialNews.WxMpMaterialNewsArticle.class);
            wxMpMaterialNews.addArticle(article);
        }// w ww. j a  v  a2 s .  c  om
    }
    return wxMpMaterialNews;
}

From source file:com.yandex.money.api.typeadapters.methods.OperationHistoryTypeAdapter.java

License:Open Source License

@Override
public OperationHistory deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {

    JsonObject object = json.getAsJsonObject();
    return new OperationHistory(Error.parse(getString(object, MEMBER_ERROR)),
            getString(object, MEMBER_NEXT_RECORD), toEmptyListIfNull(
                    OperationTypeAdapter.getInstance().fromJson(object.getAsJsonArray(MEMBER_OPERATIONS))));
}

From source file:com.yandex.money.api.typeadapters.model.DigitalGoodsTypeAdapter.java

License:Open Source License

@Override
public DigitalGoods deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {

    JsonObject object = json.getAsJsonObject();
    return new DigitalGoods(GoodTypeAdapter.getInstance().fromJson(object.getAsJsonArray(MEMBER_ARTICLE)),
            GoodTypeAdapter.getInstance().fromJson(object.getAsJsonArray(MEMBER_BONUS)));
}

From source file:com.yandex.money.api.typeadapters.model.showcase.container.ContainerTypeAdapter.java

License:Open Source License

@Override
protected void deserialize(JsonObject src, K builder, JsonDeserializationContext context) {
    for (JsonElement item : src.getAsJsonArray(MEMBER_ITEMS)) {
        builder.addItem(deserializeItem(item, context));
    }/*from   ww w .  j a va2 s.  com*/
    builder.setLabel(getString(src, MEMBER_LABEL));
}

From source file:com.yandex.money.api.typeadapters.model.showcase.ShowcaseSearchTypeAdapter.java

License:Open Source License

@Override
public ShowcaseSearch deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {

    JsonObject object = json.getAsJsonObject();
    Error error = Error.parse(getString(object, MEMBER_ERROR));
    if (error == null) {
        List<ShowcaseReference> result = ShowcaseReferenceTypeAdapter.getInstance()
                .fromJson(object.getAsJsonArray(MEMBER_RESULT));
        return ShowcaseSearch.success(result, getString(object, MEMBER_NEXT_PAGE));
    } else {//from w w w  .j a  v  a2  s. co  m
        return ShowcaseSearch.failure(error);
    }
}

From source file:com.yandex.money.api.typeadapters.model.showcase.ShowcaseTypeAdapter.java

License:Open Source License

@Override
public Showcase deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {

    JsonObject object = json.getAsJsonObject();

    Group form = null;//from ww  w .  ja  va2 s  .  c  o m
    JsonArray array = object.getAsJsonArray(MEMBER_FORM);
    if (array != null) {
        form = ListDelegate.deserialize(array, context);
    }

    List<AllowedMoneySource> moneySources = AllowedMoneySourceTypeAdapter.getInstance()
            .fromJson(object.getAsJsonArray(MEMBER_MONEY_SOURCE));
    List<Error> errors = ErrorTypeAdapter.getInstance().fromJson(object.getAsJsonArray(MEMBER_ERROR));

    return new Showcase.Builder().setTitle(getString(object, MEMBER_TITLE))
            .setHiddenFields(getNotNullMap(object, MEMBER_HIDDEN_FIELDS)).setForm(form)
            .setMoneySources(toEmptyListIfNull(moneySources)).setErrors(toEmptyListIfNull(errors)).create();
}