List of usage examples for com.google.gson JsonObject has
public boolean has(String memberName)
From source file:ch.ethz.inf.vs.hypermedia.corehal.block.CoREHalResourceFuture.java
License:Open Source License
public static JsonElement serializeToJsonTree(CoREHalBase base) { Class<? extends CoREHalBase> type = base.getClass(); if (ProxyFactory.isProxyClass(type)) { type = (Class<? extends CoREHalBase>) type.getSuperclass(); }/*from w w w .ja v a 2 s . co m*/ JsonElement s = CoREHalResourceFuture.getGson().toJsonTree(base, type); if (s.isJsonObject() && base.json() != null) { JsonObject json = s.getAsJsonObject(); base.json().entrySet().forEach((el) -> { if (!json.has(el.getKey())) { json.add(el.getKey(), el.getValue()); } }); } return s; }
From source file:ch.ethz.inf.vs.hypermedia.example.GithubBaseFuture.java
License:Open Source License
public <V extends GithubBaseFuture> V follow(String rel, Map<String, Object> parameters, Supplier<V> supplier) { V next = supplier.get();/*from w ww . j a v a2s .c o m*/ next.addParent(this); next.setPreProcess(() -> { JsonObject item = get().getAsJsonObject(); // Get next link if (item.has(rel + "_url")) { // Resolve url template String uriTemplate = item.get(rel + "_url").getAsString(); String url = UriTemplate.fromTemplate(uriTemplate).expand(parameters); // Pass resolved url to future next.setRequestURL(url); return; } next.setException(new Exception("Not found")); }); return next; }
From source file:ch.icclab.cyclops.consume.data.BillDeserializer.java
License:Open Source License
@Override public void preDeserialize(Class<? extends T> clazz, JsonElement jsonElement, Gson gson) { // valid JSON object if (jsonElement != null && jsonElement.isJsonObject()) { JsonObject root = jsonElement.getAsJsonObject(); // map data to string so it can be persisted as jsonb if (root.has(Bill.DATA_FIELD.getName())) { root.addProperty(Bill.DATA_FIELD.getName(), new Gson().toJson(root.get(Bill.DATA_FIELD.getName()))); }/*from ww w.j a v a2 s .c o m*/ } }
From source file:ch.icclab.cyclops.consume.data.CDRDeserializer.java
License:Open Source License
@Override public void preDeserialize(Class<? extends T> clazz, JsonElement jsonElement, Gson gson) { // valid JSON object if (jsonElement != null && jsonElement.isJsonObject()) { JsonObject root = jsonElement.getAsJsonObject(); // map data to string so it can be persisted as jsonb if (root.has(CDR.DATA_FIELD.getName())) { root.addProperty(CDR.DATA_FIELD.getName(), new Gson().toJson(root.get(CDR.DATA_FIELD.getName()))); }/*w ww.j a va 2 s . c o m*/ } }
From source file:ch.icclab.cyclops.consume.data.UsageDeserializer.java
License:Open Source License
@Override public void preDeserialize(Class<? extends T> clazz, JsonElement jsonElement, Gson gson) { // valid JSON object if (jsonElement != null && jsonElement.isJsonObject()) { JsonObject root = jsonElement.getAsJsonObject(); // map data to string so it can be persisted as jsonb if (root.has(Usage.DATA_FIELD.getName())) { root.addProperty(Usage.DATA_FIELD.getName(), new Gson().toJson(root.get(Usage.DATA_FIELD.getName()))); }//from www . ja va 2 s. c om } }
From source file:ch.usz.c3pro.c3_pro_android_framework.dataqueue.EncryptedDataQueue.java
License:Open Source License
/** * Decrypts a FHIR resource contained in a json object received from a C3-PRO server. *//*from w ww .j a v a 2 s . co m*/ public IBaseResource decryptResource(JsonObject jsonObject) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException, InvalidAlgorithmParameterException { if (jsonObject.has("symmetric_key") && jsonObject.has("message")) { String keyString = jsonObject.get("symmetric_key").getAsString(); String objectString = jsonObject.get("message").getAsString(); if (!Strings.isNullOrEmpty(keyString) && !Strings.isNullOrEmpty(objectString)) { byte[] keyBytes = Base64.decode(keyString, Base64.DEFAULT); byte[] objectBytes = Base64.decode(objectString, Base64.DEFAULT); SecretKey key = rsaUtility.unwrapKey(keyBytes); byte[] resourceBytes = aesUtility.deCryptData(objectBytes, key); String resourceString = new String(resourceBytes); return Pyro.getFhirContext().newJsonParser().parseResource(resourceString); } } Log.e(Logging.logTag, "The jsonObject could not be decrypted, fields are invalid: " + jsonObject.toString()); return null; }
From source file:citysdk.tourism.client.parser.POIDeserializer.java
License:Open Source License
private POIBaseType getPOIBaseType(JsonObject json) { POIBaseType base = new POIBaseType(); if (json.has(ID) && !json.get(ID).isJsonNull()) base.setId(json.get(ID).getAsString()); if (json.has(VALUE) && !json.get(VALUE).isJsonNull()) base.setValue(json.get(VALUE).getAsString()); if (json.has(HREF) && !json.get(HREF).isJsonNull()) base.setHref(json.get(HREF).getAsString()); if (json.has(TYPE) && !json.get(TYPE).isJsonNull()) base.setType(json.get(TYPE).getAsString()); if (json.has(LANG) && !json.get(LANG).isJsonNull()) base.setLang(json.get(LANG).getAsString()); if (json.has(BASE) && !json.get(BASE).isJsonNull()) base.setBase(json.get(BASE).getAsString()); try {/*from w w w.ja v a2 s . c om*/ if (json.has(CREATED) && !json.get(CREATED).isJsonNull()) base.setCreated( new SimpleDateFormat(FORMAT, Locale.ENGLISH).parse(json.get(CREATED).getAsString())); if (json.has(UPDATED) && !json.get(UPDATED).isJsonNull()) base.setCreated( new SimpleDateFormat(FORMAT, Locale.ENGLISH).parse(json.get(UPDATED).getAsString())); if (json.has(DELETED) && !json.get(DELETED).isJsonNull()) base.setCreated( new SimpleDateFormat(FORMAT, Locale.ENGLISH).parse(json.get(DELETED).getAsString())); } catch (ParseException e) { e.printStackTrace(); } if (json.has(AUTHOR) && !json.get(AUTHOR).isJsonNull()) { base.setAuthor(getPOITermType(json.get(AUTHOR).getAsJsonObject())); } if (json.has(LICENSE) && !json.get(LICENSE).isJsonNull()) { base.setAuthor(getPOITermType(json.get(LICENSE).getAsJsonObject())); } return base; }
From source file:citysdk.tourism.client.parser.POIDeserializer.java
License:Open Source License
private POITermType getPOITermType(JsonObject json) { POITermType termType = new POITermType(); if (json.has(TERM) && !json.get(TERM).isJsonNull()) termType.setTerm(json.get(TERM).getAsString()); if (json.has(VALUE) && !json.get(VALUE).isJsonNull()) termType.setValue(json.get(VALUE).getAsString()); copyTo(termType, getPOIBaseType(json)); return termType; }
From source file:citysdk.tourism.client.parser.POIDeserializer.java
License:Open Source License
private HypermediaLink getResource(JsonObject ob) { HypermediaLink hypermediaLink = new HypermediaLink(); hypermediaLink.setVersion(ob.get(VERSION).getAsString()); if (ob.has(_LINK)) { JsonObject map = ob.getAsJsonObject(_LINK); Set<Entry<String, JsonElement>> keySet = map.entrySet(); for (Entry<String, JsonElement> entry : keySet) { JsonElement element = entry.getValue(); JsonObject value = element.getAsJsonObject(); Hypermedia link = new Hypermedia(); link.setHref(value.get(HREF).getAsString()); link.setTemplated(value.get(TEMPLATED).getAsBoolean()); hypermediaLink.addHypermedia(entry.getKey(), link); }/*ww w .j ava 2 s. c o m*/ } return hypermediaLink; }
From source file:citysdk.tourism.client.parser.POIDeserializer.java
License:Open Source License
private void getRelationships(Location location, JsonArray array) { for (int i = 0; i < array.size(); i++) { JsonObject ob = array.get(i).getAsJsonObject(); Relationship r = new Relationship(); r.setTerm(ob.get(TERM).getAsString()); r.setBase(ob.get(BASE).getAsString()); if (ob.has(TARGET_POI)) r.setTargetPOI(ob.get(TARGET_POI).getAsString()); if (ob.has(TARGET_EVENT)) r.setTargetEvent(ob.get(TARGET_EVENT).getAsString()); location.addRelationship(r);//from w ww. j a va 2s. c o m } }