List of usage examples for com.google.gson JsonObject remove
public JsonElement remove(String property)
From source file:com.ibm.watson.developer_cloud.speech_to_text.v1.websocket.SpeechToTextWebSocketListener.java
License:Open Source License
/** * Builds the start message.//from w w w . java 2s . c o m * * @param options the options * @return the request */ private String buildStartMessage(RecognizeOptions options) { JsonObject startMessage = new JsonParser().parse(new Gson().toJson(options)).getAsJsonObject(); startMessage.remove(MODEL); startMessage.remove(CUSTOMIZATION_ID); startMessage.addProperty(ACTION, START); return startMessage.toString(); }
From source file:com.ibm.watson.speech_to_text.v1.websocket.SpeechToTextWebSocketListener.java
License:Open Source License
/** * Builds the start message.//from w w w . ja v a 2 s . co m * * @param options the options * @return the request */ private String buildStartMessage(RecognizeOptions options) { Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create(); JsonObject startMessage = new JsonParser().parse(gson.toJson(options)).getAsJsonObject(); startMessage.remove(MODEL); startMessage.remove(CUSTOMIZATION_ID); startMessage.remove(LANGUAGE_CUSTOMIZATION_ID); startMessage.remove(ACOUSTIC_CUSTOMIZATION_ID); startMessage.remove(VERSION); startMessage.addProperty(ACTION, START); return startMessage.toString(); }
From source file:com.intuit.wasabi.tests.service.statistic.StatisticsUtils.java
License:Apache License
static void COMPUTE_COUNT(JsonObject jsonObject) { jsonObject.remove("jointProgress"); jsonObject.remove("actionProgress"); jsonObject.remove("experimentProgress"); jsonObject.remove("jointActionRate"); jsonObject.remove("actionRates"); JsonObject cur = jsonObject.getAsJsonObject("buckets"); for (Map.Entry<String, JsonElement> entry : cur.entrySet()) { entry.getValue().getAsJsonObject().remove("actionRates"); entry.getValue().getAsJsonObject().remove("jointActionRate"); entry.getValue().getAsJsonObject().remove("bucketComparisons"); }//from w w w . ja v a2 s . co m JsonObject experimentStatistics = jsonObject.getAsJsonObject("buckets"); for (String label : new String[] { "red", "blue" }) { JsonObject bucket = experimentStatistics.getAsJsonObject(label); if (bucket.getAsJsonObject("actionCounts").entrySet().size() == 0) { experimentStatistics.remove(label); } } }
From source file:com.intuit.wasabi.tests.service.statistic.StatisticsUtils.java
License:Apache License
/** * @param jsonObject/*from w w w . j a va 2 s .c o m*/ */ static void COMPUTE_DAILY_COUNT(JsonObject jsonObject) { for (JsonElement element : jsonObject.getAsJsonArray("days")) { element.getAsJsonObject().remove("cumulative"); element.getAsJsonObject().remove("jointProgress"); element.getAsJsonObject().remove("actionProgress"); element.getAsJsonObject().remove("experimentProgress"); element.getAsJsonObject().remove("jointActionRate"); element.getAsJsonObject().remove("actionRates"); JsonObject experimentStatistics = element.getAsJsonObject().getAsJsonObject("perDay"); experimentStatistics.remove("jointActionRate"); experimentStatistics.remove("actionRates"); JsonObject buckets = experimentStatistics.getAsJsonObject("buckets"); for (String label : new String[] { "red", "blue" }) { JsonObject bucket = buckets.getAsJsonObject(label); bucket.remove("actionRates"); bucket.remove("jointActionRate"); } } }
From source file:com.itametis.jsonconverter.pathstrategy.flattener.JsonObjectFlattener.java
License:Open Source License
/** * Delete all links with other json Elements. * * @param element/*from w w w. j a va2s . c o m*/ */ protected void empty(JsonObject element) { LOGGER.debug("emptying json object {}", element.toString()); List<String> toRemove = new ArrayList<>(); for (Map.Entry<String, JsonElement> field : element.entrySet()) { toRemove.add(field.getKey()); } for (String elementToRemove : toRemove) { element.remove(elementToRemove); } }
From source file:com.jcwhatever.nucleus.storage.JsonDataNode.java
License:MIT License
private void removeKey(String[] path) { if (path.length == 1) { _root._object.remove(path[0]);//from w w w .j ava 2 s .c o m return; } JsonElement rootElement = _root._object.get(path[0]); if (rootElement == null || !rootElement.isJsonObject()) return; JsonObject object = rootElement.getAsJsonObject(); for (int i = 1; i < path.length - 1; i++) { JsonElement element = object.get(path[i]); if (element == null || !element.isJsonObject()) return; object = element.getAsJsonObject(); } object.remove(path[path.length - 1]); }
From source file:com.jcwhatever.nucleus.storage.JsonDataNode.java
License:MIT License
private void addKey(String[] path, Object value) { if (path.length == 1) { _root._object.add(path[0], _gson.toJsonTree(value)); return;/*from w w w . j a v a 2s. c om*/ } JsonElement rootElement = _root._object.get(path[0]); if (rootElement == null || !rootElement.isJsonObject()) { _root._object.remove(path[0]); _root._object.add(path[0], _gson.toJsonTree(_gson.toJsonTree(new Object()))); rootElement = _root._object.get(path[0]); } JsonObject object = rootElement.getAsJsonObject(); for (int i = 1; i < path.length - 1; i++) { JsonObject prev = object; JsonElement element = object.get(path[i]); if (element == null || !element.isJsonObject()) { prev.remove(path[i]); prev.add(path[i], _gson.toJsonTree(_gson.toJsonTree(new Object()))); element = prev.get(path[i]); } object = element.getAsJsonObject(); } if (value instanceof JsonElement) { object.add(path[path.length - 1], (JsonElement) value); } else { object.add(path[path.length - 1], _gson.toJsonTree(value)); } }
From source file:com.keydap.sparrow.SparrowClient.java
License:Apache License
/** * Serializes the given resourcetype instance * // ww w . ja va 2 s . c o m * @param rs resourcetype's instance * @return */ public <T> JsonObject serialize(T rs) { JsonObject json = (JsonObject) serializer.toJsonTree(rs); Resource r = rs.getClass().getAnnotation(Resource.class); if (r != null) { JsonArray schemas = new JsonArray(); schemas.add(r.schemaId()); Set<Field> extFields = endpointExtFieldMap.get(r.endpoint()); if (extFields != null) { for (Field f : extFields) { JsonElement je = json.remove(f.getName()); if (je != null) { Extension extSchema = f.getAnnotation(Extension.class); String schemaId = extSchema.value(); json.add(schemaId, je); schemas.add(schemaId); } } } json.add("schemas", schemas); } return json; }
From source file:com.kurento.kmf.jsonrpcconnector.JsonUtils.java
License:Open Source License
private static String extractSessionId(JsonObject jsonObject, String memberName) { JsonElement responseJson = jsonObject.get(memberName); if (responseJson != null && responseJson.isJsonObject()) { JsonObject responseJsonObject = (JsonObject) responseJson; JsonElement sessionIdJson = responseJsonObject.remove(SESSION_ID_PROPERTY); if (sessionIdJson != null && !(sessionIdJson instanceof JsonNull)) { return sessionIdJson.getAsString(); }/*from ww w. ja va 2 s . c o m*/ } return null; }
From source file:com.microsoft.windowsazure.mobileservices.JsonEntityParser.java
License:Open Source License
/** * Changes returned JSon object's id property name to match with type's id property name. * @param element/*from w w w .ja v a2 s. c o m*/ * @param propertyName */ private static void changeIdPropertyName(JsonObject element, String propertyName) { // If the property name is id or if there's no id defined, then return without performing changes if (propertyName.equals("id") || propertyName.length() == 0) return; // Get the current id value and remove the JSon property String value = element.get("id").getAsString(); element.remove("id"); // Create a new id property using the given property name element.addProperty(propertyName, value); }