List of usage examples for com.google.gson JsonElement getAsJsonObject
public JsonObject getAsJsonObject()
From source file:com.adyen.deserializer.MarketPayNotificationMessageDeserializer.java
License:MIT License
@Override public GenericNotification deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { JsonObject jsonObject = jsonElement.getAsJsonObject(); JsonElement jsonType = jsonObject.get("eventType"); String eventType = jsonType.getAsString(); if (GenericNotification.EventTypeEnum.ACCOUNT_CREATED.toString().equalsIgnoreCase(eventType)) { return jsonDeserializationContext.deserialize(jsonElement, AccountCreatedNotification.class); }// w w w . j a v a 2 s.c o m if (GenericNotification.EventTypeEnum.ACCOUNT_HOLDER_CREATED.toString().equalsIgnoreCase(eventType)) { return jsonDeserializationContext.deserialize(jsonElement, AccountHolderCreatedNotification.class); } if (GenericNotification.EventTypeEnum.ACCOUNT_HOLDER_LIMIT_REACHED.toString().equalsIgnoreCase(eventType)) { return jsonDeserializationContext.deserialize(jsonElement, AccountHolderLimitReachedNotification.class); } if (GenericNotification.EventTypeEnum.ACCOUNT_HOLDER_VERIFICATION.toString().equalsIgnoreCase(eventType)) { return jsonDeserializationContext.deserialize(jsonElement, AccountHolderVerificationNotification.class); } if (GenericNotification.EventTypeEnum.ACCOUNT_HOLDER_STATUS_CHANGE.toString().equalsIgnoreCase(eventType)) { return jsonDeserializationContext.deserialize(jsonElement, AccountHolderStatusChangeNotification.class); } if (GenericNotification.EventTypeEnum.ACCOUNT_HOLDER_PAYOUT.toString().equalsIgnoreCase(eventType)) { return jsonDeserializationContext.deserialize(jsonElement, AccountHolderPayoutNotification.class); } if (GenericNotification.EventTypeEnum.ACCOUNT_HOLDER_UPDATED.toString().equalsIgnoreCase(eventType)) { return jsonDeserializationContext.deserialize(jsonElement, AccountHolderUpdatedNotification.class); } if (GenericNotification.EventTypeEnum.BENEFICIARY_SETUP.toString().equalsIgnoreCase(eventType)) { return jsonDeserializationContext.deserialize(jsonElement, BeneficiarySetupNotification.class); } if (GenericNotification.EventTypeEnum.SCHEDULED_REFUNDS.toString().equalsIgnoreCase(eventType)) { return jsonDeserializationContext.deserialize(jsonElement, ScheduledRefundsNotification.class); } if (GenericNotification.EventTypeEnum.COMPENSATE_NEGATIVE_BALANCE.toString().equalsIgnoreCase(eventType)) { return jsonDeserializationContext.deserialize(jsonElement, CompensateNegativeBalanceNotification.class); } if (GenericNotification.EventTypeEnum.PAYMENT_FAILURE.toString().equalsIgnoreCase(eventType)) { return jsonDeserializationContext.deserialize(jsonElement, PaymentFailureNotification.class); } if (GenericNotification.EventTypeEnum.REPORT_AVAILABLE.toString().equalsIgnoreCase(eventType)) { return jsonDeserializationContext.deserialize(jsonElement, ReportAvailableNotification.class); } if (GenericNotification.EventTypeEnum.TRANSFER_FUNDS.toString().equalsIgnoreCase(eventType)) { return jsonDeserializationContext.deserialize(jsonElement, TransferFundsNotification.class); } return jsonDeserializationContext.deserialize(jsonElement, GenericNotification.class); }
From source file:com.alfresco.client.api.common.deserializer.EntryDeserializer.java
License:Apache License
@Override public T deserialize(JsonElement je, Type type, JsonDeserializationContext jdc) throws JsonParseException { JsonElement entry = je;// w w w . j ava 2 s .c om if (je.getAsJsonObject().has(PublicAPIConstant.ENTRY_VALUE)) { entry = je.getAsJsonObject().get(PublicAPIConstant.ENTRY_VALUE); } return new GsonBuilder().setDateFormat(ISO8601Utils.DATE_ISO_FORMAT).create().fromJson(entry, type); }
From source file:com.alfresco.client.api.common.deserializer.PagingDeserializer.java
License:Apache License
@Override public ResultPaging<T> deserialize(JsonElement je, Type type, JsonDeserializationContext jdc) throws JsonParseException { JsonObject pagination = null;//from w ww . j a v a 2 s.c o m JsonArray entries = null; if (je.getAsJsonObject().has(PublicAPIConstant.LIST_VALUE)) { pagination = je.getAsJsonObject().get(PublicAPIConstant.LIST_VALUE).getAsJsonObject() .get(PublicAPIConstant.PAGINATION_VALUE).getAsJsonObject(); entries = je.getAsJsonObject().get(PublicAPIConstant.LIST_VALUE).getAsJsonObject() .get(PublicAPIConstant.ENTRIES_VALUE).getAsJsonArray(); } final List<T> result = new ArrayList<>(); T obj = null; for (Object entry : entries) { obj = jdc.deserialize((JsonElement) entry, clazz); result.add(obj); } PaginationRepresentation paging = jdc.deserialize(pagination, PaginationRepresentation.class); return new ResultPaging(result, paging); }
From source file:com.alfresco.client.api.core.model.deserializer.FavoriteEntryDeserializer.java
License:Apache License
@Override public FavoriteRepresentation deserialize(JsonElement je, Type type, JsonDeserializationContext jdc) throws JsonParseException { JsonElement entry = je;// w w w . j ava 2s . c om if (je.getAsJsonObject().has(PublicAPIConstant.ENTRY_VALUE)) { entry = je.getAsJsonObject().get(PublicAPIConstant.ENTRY_VALUE); } FavoriteRepresentation favorite = null; JsonObject target = entry.getAsJsonObject().get("target").getAsJsonObject(); if (target.has("file")) { favorite = jdc.deserialize(entry, FavoriteNodeRepresentation.class); NodeRepresentation file = jdc.deserialize(target.get("file").getAsJsonObject(), NodeRepresentation.class); favorite.setTarget(file); } else if (target.has("folder")) { favorite = jdc.deserialize(entry, FavoriteNodeRepresentation.class); NodeRepresentation file = jdc.deserialize(target.get("folder").getAsJsonObject(), NodeRepresentation.class); favorite.setTarget(file); } else if (target.has("site")) { favorite = jdc.deserialize(entry, FavoriteSiteRepresentation.class); SiteRepresentation site = jdc.deserialize(target.get("site").getAsJsonObject(), SiteRepresentation.class); favorite.setTarget(site); } return favorite; }
From source file:com.alfresco.client.api.search.deserializer.ResultSetPagingDeserializer.java
License:Apache License
@Override public ResultSetRepresentation<T> deserialize(JsonElement je, Type type, JsonDeserializationContext jdc) throws JsonParseException { JsonObject contextInfo = null;/*from w ww. j a v a 2 s . c o m*/ JsonObject pagination = null; JsonArray entries = null; if (je.getAsJsonObject().has(PublicAPIConstant.LIST_VALUE)) { pagination = je.getAsJsonObject().get(PublicAPIConstant.LIST_VALUE).getAsJsonObject() .get(PublicAPIConstant.PAGINATION_VALUE).getAsJsonObject(); entries = je.getAsJsonObject().get(PublicAPIConstant.LIST_VALUE).getAsJsonObject() .get(PublicAPIConstant.ENTRIES_VALUE).getAsJsonArray(); if (je.getAsJsonObject().get(PublicAPIConstant.LIST_VALUE).getAsJsonObject() .has(PublicAPIConstant.CONTEXT_VALUE)) { contextInfo = je.getAsJsonObject().get(PublicAPIConstant.LIST_VALUE).getAsJsonObject() .get(PublicAPIConstant.CONTEXT_VALUE).getAsJsonObject(); } } final List<T> result = new ArrayList<>(); T obj = null; for (Object entry : entries) { obj = jdc.deserialize((JsonElement) entry, clazz); result.add(obj); } PaginationRepresentation paging = jdc.deserialize(pagination, PaginationRepresentation.class); ResultSetContext context = jdc.deserialize(contextInfo, ResultSetContext.class); return new ResultSetRepresentation<T>(result, context, paging); }
From source file:com.algollabs.rgx.java
License:Open Source License
/** * Handles an API Construct request./*from w w w .j av a 2s . c o m*/ * * Request JSON structure: * { * "pattern": "json_encoded_regex", * "subject": "string", * "flags": "" * } * */ private void testExpression(Request request, Response response, PrintStream stream) { try { String ptrn = null; String subj = null; String flags = null; // parse the required attributes: pattern, subject, and flags JsonElement jsonElement = parser_.parse(request.getContent()); JsonObject jsonObject = jsonElement.getAsJsonObject(); for (Entry<String, JsonElement> entry : jsonObject.entrySet()) { String k = entry.getKey(); JsonElement v = entry.getValue(); if (k.equals("pattern")) { ptrn = gson_.fromJson(v, String.class); } else if (k.equals("subject")) { subj = gson_.fromJson(v, String.class); } else if (k.equals("flags")) { flags = gson_.fromJson(v, String.class); } else { throw new UnrecognizedAttributeException(k); } } // have a Construct test the expression stream.println((new Construct(ptrn, subj, flags, true)).test()); response.setStatus(Status.OK); } catch (UnrecognizedAttributeException e) { e.printStackTrace(); response.setStatus(Status.BAD_REQUEST); stream.println(e.getMessage()); } catch (Exception e) { e.printStackTrace(); response.setStatus(Status.INTERNAL_SERVER_ERROR); stream.println(e.getMessage()); } stream.close(); }
From source file:com.aliyun.odps.udf.utils.CounterUtils.java
License:Apache License
/** * JSON{@link Counters}//from www. j a va 2 s . c o m * {@link RuntimeException} * * @param json * JSON * @return {@link Counters} * @see #toJsonString(Counters) */ public static Counters createFromJsonString(String json) { JsonParser parser = new JsonParser(); JsonElement el = parser.parse(json); return createFromJson(el.getAsJsonObject()); }
From source file:com.android.cloudfiles.cloudfilesforandroid.CloudFiles.java
License:Apache License
private void authentication(String userName, String apiKey) throws IOException { String json = generateToken(userName, apiKey); JsonParser jsonParser = new JsonParser(); JsonObject jo = (JsonObject) jsonParser.parse(json); setToken(jo.getAsJsonObject("access").getAsJsonObject("generateToken").get("id").getAsString()); JsonArray services = jo.getAsJsonObject("access").get("serviceCatalog").getAsJsonArray(); for (JsonElement jsonElement : services) { JsonObject jobj = jsonElement.getAsJsonObject(); if (jobj.get("name").getAsString().equals("cloudFiles")) { JsonArray endpoints = jobj.getAsJsonArray("endpoints"); for (JsonElement jsonElement2 : endpoints) { urls.put(jsonElement2.getAsJsonObject().get("region").getAsString(), jsonElement2.getAsJsonObject().get("publicURL").getAsString()); }/* w ww . j a v a2 s .c o m*/ } if (jobj.get("name").getAsString().equals("cloudFilesCDN")) { JsonArray endpoints = jobj.getAsJsonArray("endpoints"); for (JsonElement jsonElement2 : endpoints) { cdnUrls.put(jsonElement2.getAsJsonObject().get("region").getAsString(), jsonElement2.getAsJsonObject().get("publicURL").getAsString()); } } } }
From source file:com.apcb.utils.utils.HtmlTemplateReader.java
private SectionMatch readJson(JsonElement jsonElement, String from, SectionMatch sectionMatch) { //log.info(jsonElement.toString()); //SectionMatch sectionMatchChild = new SectionMatch(from); if (jsonElement.isJsonArray()) { //log.info("JsonArray"); JsonArray jsonArray = jsonElement.getAsJsonArray(); for (int i = 0; i < jsonArray.size(); i++) { SectionMatch sectionMatchArrayLevel = new SectionMatch(sectionMatch.getName()); sectionMatchArrayLevel.setIndex(i); sectionMatch.putChildens(readJson(jsonArray.get(i), from + "[" + i + "]", sectionMatchArrayLevel)); }//from ww w . j a va 2s . c o m } else if (jsonElement.isJsonObject()) { //log.info("JsonObject"); JsonObject jsonObject = jsonElement.getAsJsonObject(); //since you know it's a JsonObject Set<Map.Entry<String, JsonElement>> entries = jsonObject.entrySet();//will return members of your object for (Map.Entry<String, JsonElement> entry : entries) { //log.info(entry.getKey()); sectionMatch.putChildens(readJson(jsonObject.get(entry.getKey()), from + "." + entry.getKey(), new SectionMatch(entry.getKey()))); } } else if (jsonElement.isJsonNull()) { log.info("JsonNull"); } else if (jsonElement.isJsonPrimitive()) { //log.info("JsonPrimitive"); String jsonVal = jsonElement.getAsString(); //from+= "."+entry.getKey(); sectionMatch.setValue(jsonVal); log.info(from + "=" + jsonVal); } return sectionMatch; }
From source file:com.appdynamics.extensions.couchbase.CouchBaseWrapper.java
License:Apache License
/** * Gathers Cluster and Node stats. Cluster stats as Map of CLUSTER_STATS_KEY * and Map of MetricName, MetricValue and NodeStats as Map of NodeName, Map * of MetricName, MetricValue/*from w ww. j av a 2 s . c om*/ * * @param httpClient * @return */ public Map<String, Map<String, Double>> gatherClusterNodeMetrics(SimpleHttpClient httpClient) { JsonElement clusterNodeResponse = getResponse(httpClient, CLUSTER_NODE_URI); Map<String, Map<String, Double>> clusterNodeMetrics = new HashMap<String, Map<String, Double>>(); if (clusterNodeResponse != null && clusterNodeResponse.isJsonObject()) { JsonObject clusterNodeJsonObject = clusterNodeResponse.getAsJsonObject(); JsonObject storageTotals = clusterNodeJsonObject.getAsJsonObject("storageTotals"); clusterNodeMetrics = populateClusterMetrics(clusterNodeMetrics, storageTotals); JsonArray nodes = (JsonArray) clusterNodeJsonObject.get("nodes"); clusterNodeMetrics.putAll(populateNodeMetrics(nodes)); } return clusterNodeMetrics; }