List of usage examples for com.google.gson JsonObject getAsJsonObject
public JsonObject getAsJsonObject()
From source file:ch.ethz.inf.vs.hypermedia.corehal.block.CoREHalResourceFuture.java
License:Open Source License
public <X extends CoREHalResourceFuture> List<X> getEmbeddedStream(String key, Supplier<X> type) { V item = tryGet();/*from w w w. j a v a2 s. c o m*/ Iterable<Link> items = item.getLinks(key); if (items != null) { return StreamSupport.stream(items.spliterator(), false).map(x -> { X fu = type.get(); // TODO: FIX URL String url = x.getUrl(getUrl()); boolean partial = false; if (item instanceof CoREHalBase) { JsonObject embeded = getEmbeddedRepresentation(item, key, url); try { if (embeded != null) { fu.loadPartial(embeded.getAsJsonObject()); partial = true; } } catch (Exception e) { } } if (!partial) { fu.setPreProcess(() -> { fu.setRequestURL(url); }); } return fu; }).collect(Collectors.toList()); } return Collections.emptyList(); }
From source file:ch.ethz.inf.vs.hypermedia.corehal.block.CoREHalResourceFuture.java
License:Open Source License
public void loadPartial(JsonObject jsonElement) { if (getState() != READY && getState() != LOADING) throw new RuntimeException("Invalid state"); if (getState() == READY) setState(LOADING);/*from w w w . java 2 s . co m*/ try { V item = getGson().fromJson(jsonElement, createProxyClass(getType())); item.setJson(jsonElement.getAsJsonObject()); MethodHandler handler = (self, overridden, forwarder, args) -> { String methodName = overridden.getName(); if (!isPartiallyLoaded()) { return overridden.invoke(get(), args); } // Intercept call to the getter function getter access if (methodName.startsWith("get")) { String itemname = methodName.substring(3); if (methodName.equals("get")) { itemname = (String) args[0]; } else { itemname = itemname.substring(0, 1).toLowerCase() + itemname.substring(1); } // Check if field was present in the JSON object // representation if (itemname.equals("link") || itemname.equals("links")) { itemname = "_links"; } else if (itemname.equals("self")) { itemname = "_self"; } else if (itemname.equals("form") || itemname.equals("form")) { itemname = "_forms"; } else if (itemname.equals("embedded") || itemname.equals("embeddedStream")) { itemname = "_embedded"; } if (!item.json().has(itemname)) { forceFullLoad = true; if (compareAndSetState(PARTIALLY_LOADED, READY)) { LOGGER.info("Load full object " + getClass().getSimpleName() + " " + methodName); } return overridden.invoke(get(), args); } } return forwarder.invoke(self, args); }; String url = item.getSelf(getUrl()); if (!hasPreProcess()) { setPreProcess(() -> { setRequestURL(url); }); } ((ProxyObject) item).setHandler(handler); setPartial(item); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.cloudant.client.org.lightcouch.internal.GsonHelper.java
License:Open Source License
/** * Builds {@link Gson} and registers any required serializer/deserializer. * * @return {@link Gson} instance/*from w w w . j av a 2s . c om*/ */ public static GsonBuilder initGson(GsonBuilder gsonBuilder) { gsonBuilder.registerTypeAdapter(JsonObject.class, new JsonDeserializer<JsonObject>() { public JsonObject deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { return json.getAsJsonObject(); } }); gsonBuilder.registerTypeAdapter(JsonObject.class, new JsonSerializer<JsonObject>() { public JsonElement serialize(JsonObject src, Type typeOfSrc, JsonSerializationContext context) { return src.getAsJsonObject(); } }); return gsonBuilder; }
From source file:com.ericsson.eiffel.remrem.semantics.SemanticsService.java
License:Apache License
@Override public String getEventId(JsonObject json) { if (json.isJsonObject() && json.getAsJsonObject().has(META) && json.getAsJsonObject().getAsJsonObject(META).has(ID)) { return json.getAsJsonObject().getAsJsonObject(META).get(ID).getAsString(); }/*w ww.j a v a 2 s .c o m*/ return null; }
From source file:com.ericsson.eiffel.remrem.semantics.SemanticsService.java
License:Apache License
@Override public String getEventType(JsonObject json) { if (json.isJsonObject() && json.getAsJsonObject().has(META) && json.getAsJsonObject().getAsJsonObject(META).has(TYPE)) { return json.getAsJsonObject().getAsJsonObject(META).get(TYPE).getAsString(); }/* w w w. j a va 2 s. co m*/ return null; }
From source file:com.ericsson.eiffel.remrem.semantics.SemanticsService.java
License:Apache License
/** * Returns Family Routing Key Word from the messaging library based on the * eiffel message eventType./* ww w . j ava2s .c o m*/ * * @param JsonObject * eiffelMessage * @return family routing key word in String format. */ private String getFamily(JsonObject eiffelMessage) { if (eiffelMessage.isJsonObject() && eiffelMessage.getAsJsonObject().has(META) && eiffelMessage.getAsJsonObject().getAsJsonObject(META).has(TYPE)) { return event.getFamilyRoutingKey( eiffelMessage.getAsJsonObject().getAsJsonObject(META).get(TYPE).getAsString()); } return null; }
From source file:com.ericsson.eiffel.remrem.semantics.SemanticsService.java
License:Apache License
/** * Returns Type Routing Key Word from the messaging library based on the * eiffel message eventType.// w w w .ja v a2s . c o m * * @param JsonObject * eiffelMessage * @return type routing key word in String format. */ private String getType(JsonObject eiffelMessage) { if (eiffelMessage.isJsonObject() && eiffelMessage.getAsJsonObject().has(META) && eiffelMessage.getAsJsonObject().getAsJsonObject(META).has(TYPE)) { return event.getTypeRoutingKey( eiffelMessage.getAsJsonObject().getAsJsonObject(META).get(TYPE).getAsString()); } return null; }
From source file:com.ericsson.eiffel.remrem.semantics.SemanticsService.java
License:Apache License
/** * Returns the domain Id from json formatted eiffel message. * //from w w w . j av a2 s . c om * @param eiffelMessage * eiffel message in json format * @return the domainId from eiffelMessage if domainId not available then * returns the null value */ private String getDomainId(JsonObject eiffelMessage) { if (eiffelMessage.isJsonObject() && eiffelMessage.getAsJsonObject().has(META) && eiffelMessage.getAsJsonObject().getAsJsonObject(META).has(SOURCE) && eiffelMessage.getAsJsonObject().getAsJsonObject(META).getAsJsonObject(SOURCE).has(DOMAIN_ID)) { return eiffelMessage.getAsJsonObject().getAsJsonObject(META).getAsJsonObject(SOURCE).get(DOMAIN_ID) .getAsString(); } return null; }
From source file:com.ethos.business.general.ModuloEtudiantes.java
public String guardarRegistroModuloEstudiantes(JsonObject registro) throws ParseException { System.out.println("kkkkkkkkkk"); String respuesta = "NOK"; JsonObject perioAcaJsonObject;// w w w . j a v a 2 s .c o m JsonObject datosJsonObject; JsonObject paisEsculaJsonObject; JsonObject departamentoEstudioJsonObject; JsonObject ciudadEscuelaJsonObject; JsonObject fechaGraduacionJsonObject; JsonObject categoriSisbenperioAcaJsonObject; JsonObject fondoPensionesJsonObject; JsonObject epsJsonObject; SimpleDateFormat formatoFecha = new SimpleDateFormat("dd/MM/yyyy"); EstudianteModel estudiantemodel = new EstudianteModel(); perioAcaJsonObject = registro.get("periodoAca").getAsJsonObject(); datosJsonObject = registro.getAsJsonObject(); System.out.println(datosJsonObject.toString()); paisEsculaJsonObject = registro.get("paisEscuela").getAsJsonObject(); departamentoEstudioJsonObject = registro.get("depEscuela").getAsJsonObject(); ciudadEscuelaJsonObject = registro.get("ciudad").getAsJsonObject(); categoriSisbenperioAcaJsonObject = registro.get("sisben").getAsJsonObject(); epsJsonObject = registro.get("eps").getAsJsonObject(); estudiantemodel.setIdPeriodoAcademico(perioAcaJsonObject.get("idCodigo").getAsInt()); estudiantemodel.setNomEscuelaSecun(datosJsonObject.get("nomEscu").getAsString()); estudiantemodel.setIdPaisSecundaria(paisEsculaJsonObject.get("sCodigo").getAsInt()); estudiantemodel.setIdDptoSecundaria(departamentoEstudioJsonObject.get("sCodigo").getAsInt()); estudiantemodel.setIdCiudadEscuela(ciudadEscuelaJsonObject.get("sCodigo").getAsInt()); estudiantemodel.setFechaGradoSecunda(formatoFecha.parse(datosJsonObject.get("fecGraSec").getAsString())); estudiantemodel.setiCategoriaSisben(categoriSisbenperioAcaJsonObject.get("iIdCategoriaSisben").getAsInt()); estudiantemodel.setFondoPensiones(datosJsonObject.get("pensCesantias").getAsString()); estudiantemodel.setIdEps(epsJsonObject.get("id_Eps").getAsInt()); int peri = estudiantemodel.getIdPeriodoAcademico(); String n = estudiantemodel.getNomEscuelaSecun(); int p = estudiantemodel.getIdPaisSecundaria(); int d = estudiantemodel.getIdDptoSecundaria(); int c = estudiantemodel.getIdCiudadEscuela(); Date f = estudiantemodel.getFechaGradoSecunda(); int ca = estudiantemodel.getiCategoriaSisben(); String pen = estudiantemodel.getFondoPensiones(); int e = estudiantemodel.getIdEps(); String resultadoGuardarDatos = moduloCompleEstudiante.insert(estudiantemodel); String r = estudiantemodel.getNomEscuelaSecun(); System.out.println("Imprimir......" + r + "," + peri + "," + p + "," + d + "," + c + "," + f.toString() + ",z " + ca + "," + pen + "," + e); System.out.println("resultado......" + resultadoGuardarDatos); return respuesta; }
From source file:com.flipkart.android.proteus.toolbox.ColorUtils.java
License:Apache License
private static void handleElement(Context context, JsonObject value, ValueCallback<Integer> colorCallback, ValueCallback<ColorStateList> colorStateListCallback) { JsonObject jsonObject = value.getAsJsonObject(); ColorStateList colorStateList = inflateFromJson(context, jsonObject); if (null != colorStateList) { colorStateListCallback.onReceiveValue(colorStateList); }/*from www. j a va2 s .com*/ }