List of usage examples for com.google.gson JsonObject remove
public JsonElement remove(String property)
From source file:hd3gtv.mydmam.metadata.container.ContainerEntry.java
License:Open Source License
public ContainerEntry deserialize(JsonObject source, Gson gson) { JsonElement j_origin = source.get("origin"); source.remove("origin"); ContainerEntry item = internalDeserialize(source, gson); item.origin = gson.fromJson(j_origin, ContainerOrigin.class); return item;//from w w w .j av a 2 s. c o m }
From source file:hd3gtv.mydmam.transcode.images.ImageMagickAnalyser.java
License:Open Source License
public EntryAnalyser process(Container container) throws Exception { ArrayList<String> param = new ArrayList<String>(); ExecprocessGettext process = null;/* www . ja v a 2 s. com*/ try { param.addAll(convert_limits_params); param.add(container.getPhysicalSource().getPath() + "[0]"); param.add("json:-"); process = new ExecprocessGettext(convert_bin, param); process.setEndlinewidthnewline(true); process.start(); JsonParser p = new JsonParser(); JsonObject result = p.parse(process.getResultstdout().toString()).getAsJsonObject(); result = result.get("image").getAsJsonObject(); if (result.has("profiles")) { JsonObject jo_profiles = result.get("profiles").getAsJsonObject(); if (jo_profiles.has("iptc")) { /** * Import and inject IPTC */ param.clear(); param.addAll(convert_limits_params); param.add(container.getPhysicalSource().getPath() + "[0]"); param.add("iptctext:-"); process = new ExecprocessGettext(convert_bin, param); process.setEndlinewidthnewline(true); process.setExitcodemusttobe0(false); process.start(); if (process.getRunprocess().getExitvalue() == 0) { if (result.has("properties")) { ImageAttributes.injectIPTCInProperties(process.getResultstdout().toString(), result.get("properties").getAsJsonObject()); } else { JsonObject jo_properties = new JsonObject(); result.add("properties", jo_properties); ImageAttributes.injectIPTCInProperties(process.getResultstdout().toString(), jo_properties); } } } result.remove("profiles"); } result.remove("artifacts"); result.remove("name"); ImageAttributes ia = ContainerOperations.getGson().fromJson(result, ImageAttributes.class); container.getSummary().putSummaryContent(ia, ia.createSummary()); return ia; } catch (IOException e) { if (e instanceof ExecprocessBadExecutionException) { Log2Dump dump = new Log2Dump(); dump.add("param", param); if (process != null) { dump.add("stdout", process.getResultstdout().toString().trim()); dump.add("stderr", process.getResultstderr().toString().trim()); dump.add("exitcode", process.getRunprocess().getExitvalue()); } Log2.log.error("Problem with convert", null, dump); } throw e; } }
From source file:hd3gtv.mydmam.transcode.mtdcontainer.FFprobeNode.java
License:Open Source License
public final SelfSerializing deserialize(JsonObject source, Gson gson) { FFprobeNode item = create();//from ww w . j av a 2 s .co m FFprobeNodeInternalItem internal = gson.fromJson(source, getInternalItemClass()); if (source.has("tags")) { internal.tags = source.get("tags").getAsJsonObject(); source.remove("tags"); } else { internal.tags = new JsonObject(); } item.setInternalItem(internal); String[] ignore = getAdditionnaries_keys_names_to_ignore_in_params(); if (ignore != null) { for (int pos = 0; pos < ignore.length; pos++) { if (source.has(ignore[pos])) { source.remove(ignore[pos]); } } } item.params = new HashMap<String, JsonPrimitive>(); for (Map.Entry<String, JsonElement> entry : source.entrySet()) { if (entry.getValue().isJsonPrimitive()) { item.params.put(entry.getKey(), entry.getValue().getAsJsonPrimitive()); } else { Log2Dump dump = new Log2Dump(); dump.add("key", entry.getKey()); dump.add("value", entry.getValue().toString()); dump.add("source", source.toString()); Log2.log.debug("Item is not a primitive !", dump); } } return item; }
From source file:hd3gtv.mydmam.transcode.mtdgenerator.FFprobeAnalyser.java
License:Open Source License
private static void patchTagDate(JsonObject tags) { if (tags == null) { return;/* ww w. ja v a2 s . c om*/ } String key; String value; DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); HashMap<String, JsonPrimitive> new_values = new HashMap<String, JsonPrimitive>(); List<String> remove_values = new ArrayList<String>(); /** * Search and prepare changes */ for (Map.Entry<String, JsonElement> entry : tags.entrySet()) { key = (String) entry.getKey(); value = entry.getValue().getAsString(); try { if (key.equals("creation_time")) { new_values.put(key, new JsonPrimitive(format.parse(value).getTime())); } else if (key.equals("date")) { if (value.length() == "0000-00-00T00:00:00Z".length()) { new_values.put(key, new JsonPrimitive( format.parse(value.substring(0, 10) + " " + value.substring(11, 19)).getTime())); } else if (value.length() == "0000-00-00 00:00:00".length()) { new_values.put(key, new JsonPrimitive(format.parse(value).getTime())); } else if (value.length() == "0000-00-00".length()) { new_values.put(key, new JsonPrimitive(format.parse(value.substring(0, 10) + " 00:00:00").getTime())); } else { remove_values.add(key); new_values.put(key + "-raw", new JsonPrimitive("#" + value)); } } } catch (ParseException e) { Log2.log.error("Can't parse date", e, new Log2Dump("tags", tags.toString())); } } /** * Apply changes */ for (Map.Entry<String, JsonPrimitive> entry : new_values.entrySet()) { tags.add(entry.getKey(), entry.getValue()); } for (int pos = 0; pos < remove_values.size(); pos++) { tags.remove(remove_values.get(pos)); } }
From source file:io.agi.framework.persistence.PersistenceUtil.java
License:Open Source License
/** * Allows a single config property to be modified. *///from ww w . ja v a 2 s. co m private static void SetConfigProperty(String entityName, String configPath, Object value) { _logger.debug("Set config of: " + entityName + " path: " + configPath + " value: " + value); Persistence persistence = Node.NodeInstance().getPersistence(); ModelEntity modelEntity = persistence.getEntity(entityName); JsonParser parser = new JsonParser(); JsonObject root = parser.parse(modelEntity.config).getAsJsonObject(); // navigate to the nested property // N.B. String.split : http://stackoverflow.com/questions/3481828/how-to-split-a-string-in-java JsonObject parent = root; String[] pathParts = configPath.split("[.]"); int index = 0; int maxIndex = pathParts.length - 1; // NOTE: one before the one we're looking for String part = null; // if( pathParts.length < 2 ) { // i.e. 0 or 1 // part = configPath; // } while (index < maxIndex) { part = pathParts[index]; JsonElement child = parent.get(part); ++index; parent = (JsonObject) child; } part = pathParts[index]; // replace the property: parent.remove(part); if (value instanceof Boolean) { parent.addProperty(part, (Boolean) value); } else if (value instanceof Integer) { parent.addProperty(part, (Integer) value); } else if (value instanceof Float) { parent.addProperty(part, (Float) value); } else if (value instanceof Long) { parent.addProperty(part, (Long) value); } else { parent.addProperty(part, (String) value); } // re-serialize the whole thing modelEntity.config = root.toString();//getAsString(); persistence.persistEntity(modelEntity); }
From source file:io.kamax.mxisd.controller.auth.v1.AuthController.java
License:Open Source License
@RequestMapping(value = logV1Url, method = RequestMethod.POST) public String login(HttpServletRequest req) { try {/*from ww w . ja va2 s . c om*/ JsonObject reqJsonObject = parser.parse(req.getInputStream()); // find 3PID in main object GsonUtil.findPrimitive(reqJsonObject, "medium").ifPresent(medium -> { GsonUtil.findPrimitive(reqJsonObject, "address").ifPresent(address -> { log.info("Login request with medium '{}' and address '{}'", medium.getAsString(), address.getAsString()); strategy.findLocal(medium.getAsString(), address.getAsString()).ifPresent(lookupDataOpt -> { reqJsonObject.addProperty("user", lookupDataOpt.getMxid().getLocalPart()); reqJsonObject.remove("medium"); reqJsonObject.remove("address"); }); }); }); // find 3PID in 'identifier' object GsonUtil.findObj(reqJsonObject, "identifier").ifPresent(identifier -> { GsonUtil.findPrimitive(identifier, "type").ifPresent(type -> { if (StringUtils.equals(type.getAsString(), "m.id.thirdparty")) { GsonUtil.findPrimitive(identifier, "medium").ifPresent(medium -> { GsonUtil.findPrimitive(identifier, "address").ifPresent(address -> { log.info("Login request with medium '{}' and address '{}'", medium.getAsString(), address.getAsString()); strategy.findLocal(medium.getAsString(), address.getAsString()) .ifPresent(lookupDataOpt -> { identifier.addProperty("type", "m.id.user"); identifier.addProperty("user", lookupDataOpt.getMxid().getLocalPart()); identifier.remove("medium"); identifier.remove("address"); }); }); }); } if (StringUtils.equals(type.getAsString(), "m.id.phone")) { GsonUtil.findPrimitive(identifier, "number").ifPresent(number -> { GsonUtil.findPrimitive(identifier, "country").ifPresent(country -> { log.info("Login request with phone '{}'-'{}'", country.getAsString(), number.getAsString()); try { PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance(); Phonenumber.PhoneNumber phoneNumber = phoneUtil.parse(number.getAsString(), country.getAsString()); String canon_phoneNumber = phoneUtil .format(phoneNumber, PhoneNumberUtil.PhoneNumberFormat.E164) .replace("+", ""); String medium = "msisdn"; strategy.findLocal(medium, canon_phoneNumber).ifPresent(lookupDataOpt -> { identifier.addProperty("type", "m.id.user"); identifier.addProperty("user", lookupDataOpt.getMxid().getLocalPart()); identifier.remove("country"); identifier.remove("number"); }); } catch (NumberParseException e) { throw new RuntimeException(e); } }); }); } }); }); // invoke 'login' on homeserver HttpPost httpPost = RestClientUtils.post(resolveProxyUrl(req), gson, reqJsonObject); try (CloseableHttpResponse httpResponse = client.execute(httpPost)) { // check http status int status = httpResponse.getStatusLine().getStatusCode(); log.info("http status = {}", status); if (status != 200) { // try to get possible json error message from response // otherwise just get returned plain error message String errcode = String.valueOf(httpResponse.getStatusLine().getStatusCode()); String error = EntityUtils.toString(httpResponse.getEntity()); if (httpResponse.getEntity() != null) { try { JsonObject bodyJson = new JsonParser().parse(error).getAsJsonObject(); if (bodyJson.has("errcode")) { errcode = bodyJson.get("errcode").getAsString(); } if (bodyJson.has("error")) { error = bodyJson.get("error").getAsString(); } throw new RemoteLoginException(status, errcode, error, bodyJson); } catch (JsonSyntaxException e) { log.warn("Response body is not JSON"); } } throw new RemoteLoginException(status, errcode, error); } /// return response JsonObject respJsonObject = parser.parseOptional(httpResponse).get(); return gson.toJson(respJsonObject); } catch (IOException e) { throw new RuntimeException(e); } } catch (IOException e) { throw new RuntimeException(e); } }
From source file:io.openvidu.server.kurento.endpoint.KmsEvent.java
License:Apache License
public JsonObject toJson() { JsonObject json = JsonUtils.toJsonObject(event); json.remove("tags"); json.remove("timestampMillis"); json.addProperty("timestamp", timestamp); json.addProperty("session", participant.getSessionId()); json.addProperty("user", participant.getFinalUserId()); json.addProperty("connection", participant.getParticipantPublicId()); json.addProperty("endpoint", this.endpoint); json.addProperty("msSinceEndpointCreation", msSinceCreation); return json;//from w ww .j av a 2 s. c om }
From source file:io.openvidu.server.kurento.endpoint.MediaEndpoint.java
License:Apache License
public JsonObject withStatsToJson() { JsonObject json = new JsonObject(); json.addProperty("createdAt", this.createdAt); json.addProperty("webrtcEndpointName", this.getEndpointName()); json.addProperty("remoteSdp", this.getEndpoint().getRemoteSessionDescriptor()); json.addProperty("localSdp", this.getEndpoint().getLocalSessionDescriptor()); json.add("receivedCandidates", new GsonBuilder().create().toJsonTree(this.receivedCandidateList)); json.addProperty("localCandidate", this.selectedLocalIceCandidate); json.addProperty("remoteCandidate", this.selectedRemoteIceCandidate); JsonArray jsonArray = new JsonArray(); this.kmsEvents.forEach(ev -> { // Remove unwanted properties JsonObject j = ev.toJson(); j.remove("session"); j.remove("user"); j.remove("connection"); j.remove("endpoint"); j.remove("timestampMillis"); jsonArray.add(j);// w w w. j a v a 2s .c o m }); json.add("events", jsonArray); return json; }
From source file:io.openvidu.server.summary.ParticipantSummary.java
License:Apache License
public JsonObject toJson() { JsonObject json = new JsonObject(); json.addProperty("createdAt", this.eventParticipantEnd.getStartTime()); json.addProperty("destroyedAt", this.eventParticipantEnd.getTimestamp()); Participant p = this.eventParticipantEnd.getParticipant(); json.addProperty("connectionId", p.getParticipantPublicId()); json.addProperty("clientData", p.getClientMetadata()); json.addProperty("serverData", p.getServerMetadata()); long duration = (this.eventParticipantEnd.getTimestamp() - this.eventParticipantEnd.getStartTime()) / 1000; json.addProperty("duration", duration); json.addProperty("reason", this.eventParticipantEnd.getReason().name() != null ? this.eventParticipantEnd.getReason().name() : ""); // Publishers summary JsonObject publishersJson = new JsonObject(); publishersJson.addProperty("numberOfElements", publishers.size()); JsonArray jsonArrayPublishers = new JsonArray(); publishers.values().forEach(cdrEvent -> { JsonObject j = cdrEvent.toJson(); j.remove("participantId"); j.remove("connection"); jsonArrayPublishers.add(j);/*from w ww .j a va 2s. c o m*/ }); publishersJson.add("content", jsonArrayPublishers); json.add("publishers", publishersJson); // Subscribers summary JsonObject subscribersJson = new JsonObject(); subscribersJson.addProperty("numberOfElements", subscribers.size()); JsonArray jsonArraySubscribers = new JsonArray(); subscribers.values().forEach(cdrEvent -> { JsonObject j = cdrEvent.toJson(); j.remove("participantId"); j.remove("connection"); jsonArraySubscribers.add(j); }); subscribersJson.add("content", jsonArraySubscribers); json.add("subscribers", subscribersJson); return json; }
From source file:io.vertigo.vega.engines.webservice.json.GoogleJsonEngine.java
License:Apache License
private void filterFields(final JsonElement jsonElement, final Set<String> includedFields, final Set<String> excludedFields) { if (jsonElement.isJsonArray()) { final JsonArray jsonArray = jsonElement.getAsJsonArray(); for (final JsonElement jsonSubElement : jsonArray) { filterFields(jsonSubElement, includedFields, excludedFields); }/*w ww .ja v a 2s. c o m*/ } else if (jsonElement.isJsonObject()) { final JsonObject jsonObject = jsonElement.getAsJsonObject(); for (final String excludedField : excludedFields) { jsonObject.remove(excludedField); } if (!includedFields.isEmpty()) { final Set<String> notIncludedFields = new HashSet<>(); for (final Entry<String, JsonElement> entry : jsonObject.entrySet()) { if (!includedFields.contains(entry.getKey())) { notIncludedFields.add(entry.getKey()); } } for (final String notIncludedField : notIncludedFields) { jsonObject.remove(notIncludedField); } } } //else Primitive : no exclude }