List of usage examples for com.google.gson JsonElement getAsJsonObject
public JsonObject getAsJsonObject()
From source file:com.cdancy.etcd.rest.fallbacks.EtcdFallbacks.java
License:Apache License
/** * Create a Member instance from the returned Error message. * //from www . j av a 2s . c o m * @param message * error message from etcd * @return Member instance */ public static Member createMemberFromErrorMessage(String message) { JsonElement element = PARSER.parse(message); JsonObject object = element.getAsJsonObject(); ErrorMessage error = ErrorMessage.create(-1, object.get("message").getAsString(), null, -1); return Member.create(null, null, null, null, error); }
From source file:com.cinchapi.concourse.server.ConcourseServer.java
License:Apache License
/** * Do the work to jsonify (dump to json string) each of the {@code records}, * possibly at {@code timestamp} (if it is greater than 0) using the * {@code store}./* w ww. j ava2 s . c o m*/ * * @param records * @param timestamp * @param identifier - will include the primary key for each record in the * dump, if set to {@code true} * @param store * @return the json string dump */ private static String jsonify0(List<Long> records, long timestamp, boolean identifier, Store store) { JsonArray array = new JsonArray(); for (long record : records) { Map<String, Set<TObject>> data = timestamp == 0 ? store.select(record) : store.select(record, timestamp); JsonElement object = DataServices.gson().toJsonTree(data); if (identifier) { object.getAsJsonObject().addProperty(GlobalState.JSON_RESERVED_IDENTIFIER_NAME, record); } array.add(object); } return array.size() == 1 ? array.get(0).toString() : array.toString(); }
From source file:com.citrix.developer.storefront_api_android_sample.ResourceListing.java
License:Open Source License
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //R.layout.activity_resource_listing setContentView(R.layout.activity_resource_listing); Bundle bndl = this.getIntent().getExtras(); String JSONResourceList = bndl.getString("JSONRESOURCE"); //load up the listview. _appResources = new ArrayList<Resource>(); JsonParser parser = new JsonParser(); JsonElement o = parser.parse(JSONResourceList); JsonObject a = o.getAsJsonObject(); JsonArray _resources = a.get("resources").getAsJsonArray(); for (JsonElement _resource : _resources) { JsonObject _obj = _resource.getAsJsonObject(); Resource _r = new Resource(); _r.AppTitle = _obj.get("name").getAsString(); _r.AppLaunchURL = _obj.get("launchurl").getAsString(); try {// ww w. j a v a 2 s.c o m _r.AppDesc = _obj.get("description").getAsString(); } catch (Exception descException) { //do nothing } _r.AppIcon = _obj.get("iconurl").getAsString(); _appResources.add(_r); } ResourceAdapter _ra = new ResourceAdapter(this, _appResources); ListView _lv = (ListView) findViewById(R.id.resourceList); _lv.setAdapter(_ra); _lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { //get the launch URL String url = _appResources.get(i).AppLaunchURL; //call the launch task and pass it the launchURL new DownloadLaunchICATask(getApplicationContext(), ResourceListing.this).execute(url); } }); }
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// www . java 2 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 w w w.ja v a2s . com */ 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 .ja va2 s . co 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
/** * Description:/*ww w. j a va 2s . com*/ * Convert JsonElement to JsonObject, i.e. Mapping * Params: * */ protected static JsonObject convertJsonElementToJsonObject(JsonElement element) { if (element == null) { throw new XapiBadJsonObjectException("element is null"); } if (isNotJsonObject(element)) { throw new XapiBadJsonObjectException(element.getAsString() + " is not an object"); } return element.getAsJsonObject(); }
From source file:com.cloopen.rest.sdk.CCPRestSDK.java
License:Open Source License
private HashMap<String, Object> jsonToMap(String result) { HashMap<String, Object> hashMap = new HashMap<String, Object>(); JsonParser parser = new JsonParser(); JsonObject asJsonObject = parser.parse(result).getAsJsonObject(); Set<Entry<String, JsonElement>> entrySet = asJsonObject.entrySet(); HashMap<String, Object> hashMap2 = new HashMap<String, Object>(); for (Map.Entry<String, JsonElement> m : entrySet) { if ("statusCode".equals(m.getKey()) || "statusMsg".equals(m.getKey())) hashMap.put(m.getKey(), m.getValue().getAsString()); else {/*from w w w .ja v a2 s . c o m*/ if ("SubAccount".equals(m.getKey()) || "totalCount".equals(m.getKey()) || "smsTemplateList".equals(m.getKey()) || "token".equals(m.getKey()) || "callSid".equals(m.getKey()) || "state".equals(m.getKey()) || "downUrl".equals(m.getKey())) { if (!"SubAccount".equals(m.getKey()) && !"smsTemplateList".equals(m.getKey())) hashMap2.put(m.getKey(), m.getValue().getAsString()); else { try { if ((m.getValue().toString().trim().length() <= 2) && !m.getValue().toString().contains("[")) { hashMap2.put(m.getKey(), m.getValue().getAsString()); hashMap.put("data", hashMap2); break; } if (m.getValue().toString().contains("[]")) { hashMap2.put(m.getKey(), new JsonArray()); hashMap.put("data", hashMap2); continue; } JsonArray asJsonArray = parser.parse(m.getValue().toString()).getAsJsonArray(); ArrayList<HashMap<String, Object>> arrayList = new ArrayList<HashMap<String, Object>>(); for (JsonElement j : asJsonArray) { Set<Entry<String, JsonElement>> entrySet2 = j.getAsJsonObject().entrySet(); HashMap<String, Object> hashMap3 = new HashMap<String, Object>(); for (Map.Entry<String, JsonElement> m2 : entrySet2) { hashMap3.put(m2.getKey(), m2.getValue().getAsString()); } arrayList.add(hashMap3); } hashMap2.put(m.getKey(), arrayList); } catch (Exception e) { JsonObject asJsonObject2 = parser.parse(m.getValue().toString()).getAsJsonObject(); Set<Entry<String, JsonElement>> entrySet2 = asJsonObject2.entrySet(); HashMap<String, Object> hashMap3 = new HashMap<String, Object>(); for (Map.Entry<String, JsonElement> m2 : entrySet2) { hashMap3.put(m2.getKey(), m2.getValue().getAsString()); } hashMap2.put(m.getKey(), hashMap3); hashMap.put("data", hashMap2); } } hashMap.put("data", hashMap2); } else { JsonObject asJsonObject2 = parser.parse(m.getValue().toString()).getAsJsonObject(); Set<Entry<String, JsonElement>> entrySet2 = asJsonObject2.entrySet(); HashMap<String, Object> hashMap3 = new HashMap<String, Object>(); for (Map.Entry<String, JsonElement> m2 : entrySet2) { hashMap3.put(m2.getKey(), m2.getValue().getAsString()); } if (hashMap3.size() != 0) { hashMap2.put(m.getKey(), hashMap3); } else { hashMap2.put(m.getKey(), m.getValue().getAsString()); } hashMap.put("data", hashMap2); } } } return hashMap; }
From source file:com.cloud.api.IdentityTypeAdapter.java
License:Apache License
@Override public IdentityProxy deserialize(JsonElement src, Type srcType, JsonDeserializationContext context) throws JsonParseException { IdentityProxy obj = new IdentityProxy(); JsonObject json = src.getAsJsonObject(); obj.setTableName(json.get("_tableName").getAsString()); if (json.get("_value") != null) obj.setValue(json.get("_value").getAsLong()); return obj;//from w w w .jav a 2s . co m }
From source file:com.cloud.api.StringMapTypeAdapter.java
License:Apache License
@Override public Map deserialize(JsonElement src, Type srcType, JsonDeserializationContext context) throws JsonParseException { Map<String, String> obj = new HashMap<String, String>(); JsonObject json = src.getAsJsonObject(); for (Entry<String, JsonElement> entry : json.entrySet()) { obj.put(entry.getKey(), entry.getValue().getAsString()); }/* w w w . j a v a 2 s . c om*/ return obj; }