List of usage examples for com.google.gson JsonElement isJsonObject
public boolean isJsonObject()
From source file:com.ccreanga.bitbucket.rest.client.http.responseparsers.PullRequestParser.java
License:Apache License
@Override public PullRequest apply(JsonElement jsonElement) { if (jsonElement == null || !jsonElement.isJsonObject()) { return null; }/*from w w w. j a v a 2 s. co m*/ JsonObject json = jsonElement.getAsJsonObject(); //PullRequest pullRequest = new PullRequest(); PullRequestParticipant author = pullRequestParticipantParser().apply(json.getAsJsonObject("author")); List<PullRequestParticipant> reviewers = listParser(pullRequestParticipantParser()) .apply(json.get("reviewers")); List<PullRequestParticipant> participants = listParser(pullRequestParticipantParser()) .apply(json.get("participants")); PullRequestBranch from = pullRequestBranchParser().apply(json.getAsJsonObject("fromRef")); PullRequestBranch to = pullRequestBranchParser().apply(json.getAsJsonObject("toRef")); String selfUrl = null; if (json.has("links")) { selfUrl = linkParser().apply(json.getAsJsonObject("links").get("self").getAsJsonArray().get(0)) .getHref(); } return new PullRequest(json.get("id").getAsLong(), json.get("version").getAsLong(), json.get("title").getAsString(), optionalJsonString(json, "description"), PullRequestState.valueOf(json.get("state").getAsString()), json.get("open").getAsBoolean(), json.get("closed").getAsBoolean(), new Date(json.get("createdDate").getAsLong()), new Date(json.get("updatedDate").getAsLong()), from, to, optionalJsonBoolean(json, "locked"), author, reviewers, participants, selfUrl); }
From source file:com.ccreanga.bitbucket.rest.client.http.responseparsers.RepositoryParser.java
License:Apache License
@Override public Repository apply(JsonElement jsonElement) { if (jsonElement == null || !jsonElement.isJsonObject()) { return null; }/*from w w w . j av a2 s. c o m*/ JsonObject json = jsonElement.getAsJsonObject(); String sshCloneUrl = null; String httpCloneUrl = null; String selfUrl = null; if (json.has("links")) { JsonObject links = json.getAsJsonObject("links"); selfUrl = linkParser("url", "text").apply(links.get("self").getAsJsonArray().get(0)).getHref(); if (links.has("clone")) { JsonArray arrayCloneLinks = links.get("clone").getAsJsonArray(); Link first = linkParser().apply(arrayCloneLinks.get(0)); Link second = linkParser().apply(arrayCloneLinks.get(1)); if (first.getName().equals("http")) { httpCloneUrl = first.getHref(); sshCloneUrl = second.getHref(); } else { sshCloneUrl = first.getHref(); httpCloneUrl = second.getHref(); } } } return new Repository(optionalJsonString(json, "hierarchyId"), json.get("id").getAsLong(), json.get("slug").getAsString(), json.get("name").getAsString(), optionalJsonBoolean(json, "public"), optionalJsonBoolean(json, "fork"), optionalJsonBoolean(json, "forkable"), sshCloneUrl, httpCloneUrl, selfUrl, projectParser().apply(json.getAsJsonObject("project")), json.has("origin") ? repositoryParser().apply(json.getAsJsonObject("origin")) : null, json.get("scmId").getAsString(), RepositoryState.valueOf(json.get("state").getAsString()), json.get("statusMessage").getAsString()); }
From source file:com.ccreanga.bitbucket.rest.client.http.responseparsers.TaskOperationsParser.java
License:Apache License
@Override public TaskOperations apply(JsonElement jsonElement) { if (jsonElement == null || !jsonElement.isJsonObject()) { return null; }//from www . j a v a 2 s. c o m JsonObject json = jsonElement.getAsJsonObject(); return new TaskOperations(json.get("editable").getAsBoolean(), json.get("deletable").getAsBoolean(), json.get("transitionable").getAsBoolean()); }
From source file:com.ccreanga.bitbucket.rest.client.http.responseparsers.TaskParser.java
License:Apache License
@Override public Task apply(JsonElement jsonElement) { if (jsonElement == null || !jsonElement.isJsonObject()) { return null; }/*from www.j a va2s.c o m*/ JsonObject json = jsonElement.getAsJsonObject(); return new Task(json.get("id").getAsLong(), TaskState.valueOf(json.get("state").getAsString()), json.get("text").getAsString(), new Date(json.get("createdDate").getAsLong()), commentParser().apply(json.getAsJsonObject("anchor")), userParser().apply(json.getAsJsonObject("author")), taskOperationsParser().apply(json.getAsJsonObject("permittedOperations"))); }
From source file:com.citrus.sdk.CitrusClient.java
License:Apache License
/** * Get the merchant available payment options. You need to show the user available payment option in your app. * * @param callback//from ww w.j av a2 s . c om */ public synchronized void getMerchantPaymentOptions(final Callback<MerchantPaymentOption> callback) { if (validate()) { if (merchantPaymentOption == null) { retrofitClient.getMerchantPaymentOptions(vanity, new retrofit.Callback<JsonElement>() { @Override public void success(JsonElement element, Response response) { MerchantPaymentOption merchantPaymentOption; if (element.isJsonObject()) { JsonObject paymentOptionObj = element.getAsJsonObject(); if (paymentOptionObj != null) { merchantPaymentOption = MerchantPaymentOption .getMerchantPaymentOptions(paymentOptionObj); // Store merchant payment options locally. setMerchantPaymentOption(merchantPaymentOption); sendResponse(callback, merchantPaymentOption); } else { sendError(callback, new CitrusError( ResponseMessages.ERROR_MESSAGE_FAILED_MERCHANT_PAYMENT_OPTIONS, Status.FAILED)); } } else { sendError(callback, new CitrusError(ResponseMessages.ERROR_MESSAGE_INVALID_JSON, Status.FAILED)); } } @Override public void failure(RetrofitError error) { sendError(callback, error); } }); } else { sendResponse(callback, merchantPaymentOption); } } }
From source file:com.citrus.sdk.CitrusClient.java
License:Apache License
/** * Get the payment options available for load money. You need to show the user available payment option in your app. * * @param callback//from ww w . j a va2s.co m */ public synchronized void getLoadMoneyPaymentOptions(final Callback<MerchantPaymentOption> callback) { if (validate()) { retrofitClient.getMerchantPaymentOptions(Constants.PREPAID_VANITY, new retrofit.Callback<JsonElement>() { @Override public void success(JsonElement element, Response response) { MerchantPaymentOption merchantPaymentOption; if (element.isJsonObject()) { JsonObject paymentOptionObj = element.getAsJsonObject(); if (paymentOptionObj != null) { merchantPaymentOption = MerchantPaymentOption .getMerchantPaymentOptions(paymentOptionObj); sendResponse(callback, merchantPaymentOption); } else { sendError(callback, new CitrusError( ResponseMessages.ERROR_MESSAGE_FAILED_MERCHANT_PAYMENT_OPTIONS, Status.FAILED)); } } else { sendError(callback, new CitrusError(ResponseMessages.ERROR_MESSAGE_INVALID_JSON, Status.FAILED)); } } @Override public void failure(RetrofitError error) { sendError(callback, error); } }); } }
From source file:com.citrus.sdk.payment.MerchantPaymentOption.java
License:Apache License
public static MerchantPaymentOption getMerchantPaymentOptions(JsonObject merchantPaymentOptionsObj, Map<String, PGHealth> pgHealthMap) { MerchantPaymentOption merchantPaymentOption; Set<CardScheme> debitCardSchemeSet = null; Set<CardScheme> creditCardSchemeSet = null; ArrayList<NetbankingOption> netbankingOptionList = null; JsonArray bankArray = merchantPaymentOptionsObj.getAsJsonArray("netBanking"); JsonArray creditCardArray = merchantPaymentOptionsObj.getAsJsonArray("creditCard"); JsonArray debitCardArray = merchantPaymentOptionsObj.getAsJsonArray("debitCard"); int size = -1; // Parse credit card scheme size = creditCardArray.size();/*from ww w . j av a 2 s.c o m*/ for (int i = 0; i < size; i++) { JsonElement element = creditCardArray.get(i); String cardScheme = element.getAsString(); if (creditCardSchemeSet == null) { creditCardSchemeSet = new HashSet<>(); } creditCardSchemeSet.add(getCardScheme(cardScheme)); } // Parse debit card scheme size = debitCardArray.size(); for (int i = 0; i < size; i++) { JsonElement element = debitCardArray.get(i); String cardScheme = element.getAsString(); if (debitCardSchemeSet == null) { debitCardSchemeSet = new HashSet<>(); } debitCardSchemeSet.add(getCardScheme(cardScheme)); } // Parse netbanking options size = bankArray.size(); for (int i = 0; i < size; i++) { JsonElement element = bankArray.get(i); if (element.isJsonObject()) { JsonObject bankOption = element.getAsJsonObject(); element = bankOption.get("bankName"); String bankName = element.getAsString(); element = bankOption.get("issuerCode"); String issuerCode = element.getAsString(); if (!TextUtils.isEmpty(bankName) && !TextUtils.isEmpty(issuerCode)) { NetbankingOption netbankingOption = new NetbankingOption(bankName, issuerCode); if (pgHealthMap != null) { netbankingOption.setPgHealth(pgHealthMap.get(issuerCode)); } if (netbankingOptionList == null) { netbankingOptionList = new ArrayList<>(); } netbankingOptionList.add(netbankingOption); } } } merchantPaymentOption = new MerchantPaymentOption(creditCardSchemeSet, debitCardSchemeSet, netbankingOptionList); return merchantPaymentOption; }
From source file:com.claresco.tinman.json.JsonUtility.java
License:Open Source License
protected static boolean isJsonObject(JsonElement theElement) { return theElement.isJsonObject(); }
From source file:com.claresco.tinman.json.XapiPersonJson.java
License:Open Source License
@Override public XapiPerson deserialize(JsonElement arg0, Type arg1, JsonDeserializationContext arg2) throws JsonParseException { if (arg0.isJsonObject()) { JsonObject theJsonObject = JsonUtility.convertJsonElementToJsonObject(arg0); ArrayList<String> theName = fillTheList("name", theJsonObject); ArrayList<String> theMboxSha1sum = fillTheList("mbox_sha1sum", theJsonObject); ArrayList<String> theOpenid = fillTheList("openid", theJsonObject); ArrayList<XapiIRI> theMbox = new ArrayList<XapiIRI>(); ArrayList<XapiAccount> theAccounts = new ArrayList<XapiAccount>(); JsonArray theArray;/* www .jav a2 s .c o m*/ if (JsonUtility.hasElement(theJsonObject, "mbox")) { theArray = JsonUtility.getAnArray(theJsonObject, "mbox"); for (JsonElement e : theArray) { if (!e.isJsonNull()) { String theEmailAddress = e.getAsString(); if (!theEmailAddress.startsWith("mailto:")) { throw new XapiBadIdentifierException("Mbox has to start with \'mailto:\'"); } theMbox.add(new XapiIRI(e.getAsString())); } } } if (JsonUtility.hasElement(theJsonObject, "account")) { theArray = JsonUtility.getAnArray(theJsonObject, "account"); for (JsonElement e : theArray) { theAccounts.add((XapiAccount) JsonUtility.delegateDeserialization(arg2, e, XapiAccount.class)); } } return new XapiPerson(theName, theMbox, theMboxSha1sum, theOpenid, theAccounts); } else { throw new XapiBadPersonException("XapiPerson should be a JSON object"); } }
From source file:com.cloudant.client.internal.views.RowImpl.java
License:Open Source License
RowImpl(ViewQueryParameters<K, V> parameters, JsonElement row) { this.parameters = parameters; this.gson = parameters.getClient().getGson(); if (row.isJsonObject()) { this.row = row.getAsJsonObject(); } else {/*from w w w .jav a2s . c o m*/ this.row = new JsonObject(); } }