List of usage examples for com.google.gson JsonObject entrySet
public Set<Map.Entry<String, JsonElement>> entrySet()
From source file:com.ccreanga.bitbucket.rest.client.http.responseparsers.BuildStatsParser.java
License:Apache License
@Override public Map<String, BuildStatsSummary> apply(JsonElement jsonElement) { JsonObject json = jsonElement.getAsJsonObject(); ImmutableMap.Builder<String, BuildStatsSummary> builder = ImmutableMap.builder(); for (Map.Entry<String, JsonElement> commitEntries : json.entrySet()) { BuildStatsSummary.Builder element = BuildStatsSummary.builder(); for (Map.Entry<String, JsonElement> e : commitEntries.getValue().getAsJsonObject().entrySet()) { if ("failed".equals(e.getKey())) { element.setFailed(e.getValue().getAsLong()); } else if ("inProgress".equals(e.getKey())) { element.setInProgress(e.getValue().getAsLong()); } else if ("successful".equals(e.getKey())) { element.setSuccessful(e.getValue().getAsLong()); }//from ww w . j a v a 2 s. com } builder.put(commitEntries.getKey(), element.build()); } return builder.build(); }
From source file:com.chatwing.whitelabel.managers.ApiManagerImpl.java
License:Apache License
protected String appendParams(Object params) { StringBuilder builder = new StringBuilder(); builder.append("?"); Gson gson = new Gson(); JsonObject gsonObject = gson.toJsonTree(params).getAsJsonObject(); for (Map.Entry<String, JsonElement> entry : gsonObject.entrySet()) { JsonElement value = entry.getValue(); if (value != null && value.isJsonPrimitive()) { try { builder.append(URLEncoder.encode(entry.getKey(), "UTF-8")); builder.append("="); builder.append(URLEncoder.encode(value.getAsString(), "UTF-8")); builder.append("&"); } catch (UnsupportedEncodingException e) { e.printStackTrace();//from w w w . j a v a 2s .c o m } } } return builder.toString(); }
From source file:com.claresco.tinman.json.XapiActivityDefinitionJson.java
License:Open Source License
@Override public XapiActivityDefinition deserialize(JsonElement arg0, Type arg1, JsonDeserializationContext arg2) throws JsonParseException { if (JsonUtility.isJsonElementNull(arg0)) { return null; }// w w w . j a v a 2s.co m JsonObject theActivityDefinition = JsonUtility.convertJsonElementToJsonObject(arg0); // Construct the name XapiLanguageMap theName = JsonUtility.constructLanguageMap(theActivityDefinition, "name"); // Construct the description XapiLanguageMap theDescription = JsonUtility.constructLanguageMap(theActivityDefinition, "description"); String theType = JsonUtility.getElementAsString(theActivityDefinition, "type"); String theMoreInfo = JsonUtility.getElementAsString(theActivityDefinition, "moreInfo"); XapiInteraction theInteraction = null; XapiExtension theExtension = null; // If activity has interaction, delegate it if (theType != null && JsonUtility.isActivityOfTypeInteraction(theType)) { theInteraction = JsonUtility.delegateDeserialization(arg2, arg0, XapiInteraction.class); } // Check for extension if (JsonUtility.hasElement(theActivityDefinition, "extensions")) { JsonElement theExtJson = JsonUtility.get(theActivityDefinition, "extensions"); JsonObject extJsonMap = JsonUtility.convertJsonElementToJsonObject(theExtJson); theExtension = new XapiExtension(); for (Map.Entry<String, JsonElement> entry : extJsonMap.entrySet()) { JsonElement theValue = entry.getValue(); if (theValue.isJsonPrimitive()) { theExtension.add(entry.getKey(), entry.getValue().getAsString()); } else { theExtension.add(entry.getKey(), entry.getValue().toString()); } } } if (theExtension != null && theExtension.isEmpty()) { return new XapiActivityDefinition(theName, theDescription, theType, theMoreInfo, theInteraction, null); } return new XapiActivityDefinition(theName, theDescription, theType, theMoreInfo, theInteraction, theExtension); }
From source file:com.claresco.tinman.json.XapiExtensionsJson.java
License:Open Source License
@Override public XapiExtension deserialize(JsonElement arg0, Type arg1, JsonDeserializationContext arg2) throws JsonParseException { JsonObject extensionJsonMap = JsonUtility.convertJsonElementToJsonObject(arg0); XapiExtension theExtension = new XapiExtension(); for (Map.Entry<String, JsonElement> entry : extensionJsonMap.entrySet()) { JsonElement theValue = entry.getValue(); if (theValue.isJsonPrimitive()) { theExtension.add(entry.getKey(), entry.getValue().getAsString()); } else {/*from w w w .ja v a 2 s . c o m*/ theExtension.add(entry.getKey(), entry.getValue().toString()); } } return theExtension; }
From source file:com.claresco.tinman.json.XapiLanguageMapJson.java
License:Open Source License
@Override public XapiLanguageMap deserialize(JsonElement arg0, Type arg1, JsonDeserializationContext arg2) throws JsonParseException { JsonObject theLMapJSON = JsonUtility.convertJsonElementToJsonObject(arg0); XapiLanguageMap theLMap = new XapiLanguageMap(); for (Map.Entry<String, JsonElement> entry : theLMapJSON.entrySet()) { theLMap.registerLanguage(entry.getKey(), entry.getValue().getAsString()); }/*from www . j a va 2 s .c o m*/ return theLMap; }
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 {// w w w.j av a 2 s. co 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.agent.transport.ArrayTypeAdaptor.java
License:Apache License
@Override @SuppressWarnings("unchecked") public T[] deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonArray array = json.getAsJsonArray(); Iterator<JsonElement> it = array.iterator(); ArrayList<T> cmds = new ArrayList<T>(); while (it.hasNext()) { JsonObject element = (JsonObject) it.next(); Map.Entry<String, JsonElement> entry = element.entrySet().iterator().next(); String name = s_pkg + entry.getKey(); Class<?> clazz;/*w ww . j av a 2 s. co m*/ try { clazz = Class.forName(name); } catch (ClassNotFoundException e) { throw new CloudRuntimeException("can't find " + name); } T cmd = (T) _gson.fromJson(entry.getValue(), clazz); cmds.add(cmd); } Class<?> type = ((Class<?>) typeOfT).getComponentType(); T[] ts = (T[]) Array.newInstance(type, cmds.size()); return cmds.toArray(ts); }
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()); }//from www . j a va 2 s . co m return obj; }
From source file:com.cloudbase.CBNaturalDeserializer.java
License:Open Source License
private Object handleObject(JsonObject json, JsonDeserializationContext context) { Map<String, Object> map = new HashMap<String, Object>(); for (Map.Entry<String, JsonElement> entry : json.entrySet()) map.put(entry.getKey(), context.deserialize(entry.getValue(), Object.class)); return map;/* w ww. j av a 2s . c o m*/ }
From source file:com.codereligion.bugsnag.logback.resource.TabVOSerializer.java
License:Apache License
private void filterJsonObject(final JsonObject jsonObject) { for (final Map.Entry<String, JsonElement> entry : jsonObject.entrySet()) { final String key = entry.getKey(); if (jsonFilterProvider.isIgnoredByFilter(key)) { jsonObject.remove(key);/* ww w . j ava2 s .c om*/ } else { filterJsonElement(entry.getValue()); } } }