List of usage examples for com.google.gson JsonObject remove
public JsonElement remove(String property)
From source file:org.microworld.mangopay.implementation.DefaultMangopayConnection.java
License:Apache License
private String toJson(final Object data) { final JsonObject jsonObject = gson.toJsonTree(data).getAsJsonObject(); jsonObject.remove("Id"); jsonObject.remove("CreationDate"); return gson.toJson(jsonObject); }
From source file:org.microworld.mangopay.implementation.DefaultMangopayConnection.java
License:Apache License
private PayIn convertBankWirePayIn(final JsonObject object) { final JsonObject bankAccount = object.remove("BankAccount").getAsJsonObject(); final BankWirePayIn payIn = gson.fromJson(object, BankWirePayIn.class); setFieldValue(BankWirePayIn.class, "bankAccount", payIn, convertBankAccount(bankAccount)); return payIn; }
From source file:org.mobicents.servlet.restcomm.rvd.upgrade.ProjectUpgrader10to11.java
License:Open Source License
/** * Set project vesion to newVersion. Assumes "root.header.version" existence introduced * in project version 1.0// w w w . ja v a 2 s.com * * @param root * @param newVersion * @return the same root JsonElement it was given (for easy chaining) */ public static JsonElement setVersion(JsonElement root, String newVersion) { JsonObject header = root.getAsJsonObject().get("header").getAsJsonObject(); header.remove("version"); header.addProperty("version", newVersion); return root; }
From source file:org.mobicents.servlet.restcomm.rvd.upgrade.ProjectUpgrader15to16.java
License:Open Source License
public static JsonElement upgradeNumericCollectMenu(JsonElement rootElement) { JsonElement nodesElement = rootElement.getAsJsonObject().get("nodes"); if (nodesElement != null) { JsonArray nodes = nodesElement.getAsJsonArray(); for (int i = 0; i < nodes.size(); i++) { JsonObject node = nodes.get(i).getAsJsonObject(); String kind = node.get("kind").getAsString(); if ("voice".equals(kind)) { JsonElement stepsElement = node.get("steps"); if (stepsElement != null) { JsonArray steps = stepsElement.getAsJsonArray(); for (int steps_i = 0; steps_i < steps.size(); steps_i++) { JsonObject step = steps.get(steps_i).getAsJsonObject(); String stepkind = step.get("kind").getAsString(); if ("gather".equals(stepkind)) { JsonElement menuElement = step.get("menu"); if (menuElement != null) { JsonElement mappingsElement = menuElement.getAsJsonObject().get("mappings"); if (mappingsElement != null) { JsonArray mappings = mappingsElement.getAsJsonArray(); for (int mappings_i = 0; mappings_i < mappings.size(); mappings_i++) { JsonObject mapping = mappings.get(mappings_i).getAsJsonObject(); // convert 'digits' from integer to string Integer digits = mapping.get("digits").getAsInt(); mapping.remove("digits"); mapping.addProperty("digits", digits.toString()); }//from w w w. ja v a2 s . c o m } } } } } } // handle other project kinds here (sms,ussd) } } return rootElement; }
From source file:org.mule.modules.box.jersey.json.SearchResponseDeserealizer.java
License:Open Source License
@Override public SearchResponse deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject object = null; if (json.isJsonObject()) { object = json.getAsJsonObject(); } else {//w w w .ja va 2 s . c o m throw new RuntimeException("Json element is not an object"); } Gson gson = GsonFactory.getRawInstance(); JsonElement entries = object.remove("entries"); SearchResponse response = gson.fromJson(json, SearchResponse.class); response.setEntries(this.parseEntries(entries, gson)); return response; }
From source file:org.mule.modules.servicesource.ApiResponseDeserealizer.java
License:Open Source License
private void deserealizeData(JsonObject json, ApiResponse<Object> response) { JsonElement dataElement = json.get("data"); if (dataElement == null) { return;/*ww w .j a v a 2 s .c o m*/ } JsonObject data = dataElement.getAsJsonObject(); Set<Map.Entry<String, JsonElement>> entrySet = data.entrySet(); if (entrySet.isEmpty()) { throw new IllegalArgumentException("data element contained no elements"); } List<Object> records = new ArrayList<Object>(); Gson gson = GsonFactory.getGson(); for (Map.Entry<String, JsonElement> entry : entrySet) { ServiceSourceCollection collection = ServiceSourceCollection.getByEntityName(entry.getKey()); if (collection != null) { Class<?> type = collection.getType(); for (JsonElement element : entry.getValue().getAsJsonArray()) { JsonObject object = element.getAsJsonObject(); JsonElement extensionElement = element.getAsJsonObject().get("extensions"); if (extensionElement != null) { object.remove("extensions"); } ServiceSourceEntity entity = (ServiceSourceEntity) gson.fromJson(element, type); records.add(entity); if (extensionElement != null && extensionElement.isJsonObject()) { entity.setExtensions(this.json2Map(extensionElement.getAsJsonObject())); } } } else { JsonElement unknownElement = entry.getValue(); if (unknownElement.isJsonArray()) { for (JsonElement element : unknownElement.getAsJsonArray()) { records.add(this.json2Map(element.getAsJsonObject())); } } else if (unknownElement.isJsonObject()) { records.add(this.json2Map(unknownElement.getAsJsonObject())); } } } response.setRecords(records); }
From source file:org.mule.modules.servicesource.RelationTargetDeserealizer.java
License:Open Source License
@Override public RelationTarget deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { Gson gson = GsonFactory.getRawInstance(); JsonObject object = json.getAsJsonObject(); JsonElement relationshipsJson = object.remove("relationships"); RelationTarget target = gson.fromJson(json, RelationTarget.class); if (relationshipsJson != null) { List<RelationshipCycle> relationships = null; if (relationshipsJson.isJsonArray()) { Type collectionType = new TypeToken<Collection<RelationshipCycle>>() { }.getType();// w ww. ja va 2s . co m relationships = gson.fromJson(json, collectionType); } else if (relationshipsJson.isJsonObject()) { if (!relationshipsJson.toString().trim().replaceAll(" ", "").equals("{}")) { relationships = new ArrayList<RelationshipCycle>(1); relationships.add(gson.fromJson(relationshipsJson, RelationshipCycle.class)); } } target.setRelationships(relationships); } return target; }
From source file:org.mycore.datamodel.metadata.MCRObjectService.java
License:Open Source License
/** * Creates the JSON representation of this service. * /*from w w w . j a va 2s .c o m*/ * <pre> * { * dates: [ * {@link MCRMetaISO8601Date#createJSON()}, * ... * ], * rules: [ * {@link MCRMetaAccessRule#createJSON()}, * ... * ], * flags: [ * {@link MCRMetaLangText#createJSON()}, * ... * ], * state: { * * } * } * </pre> * * @return a json gson representation of this service */ public final JsonObject createJSON() { JsonObject service = new JsonObject(); // dates if (!getDates().isEmpty()) { JsonObject dates = new JsonObject(); getDates().stream().forEachOrdered(date -> { JsonObject jsonDate = date.createJSON(); jsonDate.remove("type"); dates.add(date.getType(), jsonDate); }); service.add("dates", dates); } // rules if (!getRules().isEmpty()) { JsonArray rules = new JsonArray(); getRules().stream().map(MCRMetaAccessRule::createJSON).forEachOrdered(rules::add); service.add("rules", rules); } // flags if (!getFlags().isEmpty()) { JsonArray flags = new JsonArray(); getFlagsAsList().stream().map(MCRMetaLangText::createJSON).forEachOrdered(flags::add); service.add("flags", flags); } // state Optional.ofNullable(getState()).ifPresent(stateId -> { JsonObject state = new JsonObject(); if (stateId.getID() != null) { state.addProperty("id", stateId.getID()); } state.addProperty("rootId", stateId.getRootID()); }); return service; }
From source file:org.nines.RDFIndexer.java
License:Apache License
private void updateDocumentReferences(final JsonObject json) { String fl = config.getFieldList(); String coreName = config.coreName(); String uri = json.get("uri").getAsString(); boolean updated = false; try {/*from w ww .j a va 2 s . com*/ if (json.has(isPartOf) == true) { JsonArray refs = json.getAsJsonArray(isPartOf); //log.info( "isPartOf: " + refs.toString( ) ); JsonArray objs = new JsonArray(); for (int ix = 0; ix < refs.size(); ix++) { List<String> andList = new ArrayList<String>(); andList.add("uri=" + URLEncoder.encode("\"" + refs.get(ix).getAsString() + "\"", "UTF-8")); List<JsonObject> results = this.solrClient.getResultsPage(coreName, config.archiveName, 0, 1, fl, andList, null); if (results.isEmpty() == false) { objs.add(removeExcessFields(results.get(0))); } else { // reference to a non-existent object, note in the error log IndexerError e = new IndexerError("", uri, "Cannot resolve isPartOf reference (" + refs.get(ix).getAsString() + ") for document " + uri); errorReport.addError(e); } } // remove the field; we may replace it with resolved data json.remove(isPartOf); updated = true; // did we resolve any of the references if (objs.size() != 0) { //log.info( "UPDATING isPartOf: " + objs.toString( ) ); json.addProperty(isPartOf, objs.toString()); } } if (json.has(hasPart) == true) { JsonArray refs = json.getAsJsonArray(hasPart); //log.info( "hasPart: " + refs.toString( ) ); JsonArray objs = new JsonArray(); for (int ix = 0; ix < refs.size(); ix++) { List<String> andList = new ArrayList<String>(); andList.add("uri=" + URLEncoder.encode("\"" + refs.get(ix).getAsString() + "\"", "UTF-8")); List<JsonObject> results = this.solrClient.getResultsPage(coreName, config.archiveName, 0, 1, fl, andList, null); if (results.isEmpty() == false) { objs.add(removeExcessFields(results.get(0))); } else { // reference to a non-existent object, note in the error log IndexerError e = new IndexerError("", uri, "Cannot resolve hasPart reference (" + refs.get(ix).getAsString() + ") for document " + uri); errorReport.addError(e); } } // remove the field; we may replace it with resolved data json.remove(hasPart); updated = true; if (objs.size() != 0) { //log.info( "UPDATING hasPart: " + objs.toString( ) ); json.addProperty(hasPart, objs.toString()); } } if (updated == true) { this.jsonPayload.add(json); flushIfEnough(); } } catch (UnsupportedEncodingException ex) { // should never happen } }
From source file:org.nines.RDFIndexer.java
License:Apache License
private JsonObject removeExcessFields(JsonObject json) { json.remove(isPartOf); json.remove(hasPart);//from w ww . j a v a2 s. c om json.remove("text"); json.remove("_version_"); json.remove("year_sort_desc"); json.remove("federation"); json.remove("year"); json.remove("decade"); json.remove("year_sort"); json.remove("year_sort_asc"); json.remove("title_sort"); json.remove("author_sort"); json.remove("date_created"); json.remove("date_updated"); json.remove("century"); json.remove("half_century"); json.remove("quarter_century"); return (json); }