List of usage examples for com.google.gson JsonElement getAsJsonObject
public JsonObject getAsJsonObject()
From source file:co.cask.tigon.internal.app.FlowletSpecificationCodec.java
License:Apache License
@Override public FlowletSpecification deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); String className = jsonObj.get("className").getAsString(); String name = jsonObj.get("name").getAsString(); String description = jsonObj.get("description").getAsString(); FailurePolicy policy = FailurePolicy.valueOf(jsonObj.get("failurePolicy").getAsString()); Map<String, String> properties = deserializeMap(jsonObj.get("properties"), context, String.class); ResourceSpecification resources = context.deserialize(jsonObj.get("resources"), new TypeToken<ResourceSpecification>() { }.getType());/*w ww.j a v a2s . c o m*/ int maxInstances = jsonObj.get("maxInstances").getAsInt(); return new DefaultFlowletSpecification(className, name, description, policy, properties, resources, maxInstances); }
From source file:co.edu.poli.util.jqgrid.JqGridData.java
public void getJsonObject(String j) { /*String j = "{groupOp:OR,rules:[{field:id_encabezado,op:cn,data:prueba}," + "{field:modulo,op:cn,data:prueba}," + "{field:norma,op:cn,data:prueba}," + "{field:resultado,op:cn,data:prueba}," + "{field:evidencia,op:cn,data:prueba}," + "{field:elemento,op:cn,data:prueba}," + "{field:descripcion_encab,op:cn,data:prueba98}]}";*/ filtersArr = new HashMap(); Gson gson = new Gson(); JsonElement jelement = new JsonParser().parse(j); JsonObject jobject = jelement.getAsJsonObject(); filtersArr.put("groupOp", jobject.get("groupOp")); JsonArray array = jobject.getAsJsonArray("rules"); ArrayList<filter> f = new ArrayList<>(); for (int i = 0; i < array.size(); i++) { {/*w ww . java 2 s .com*/ JsonObject cont = array.get(i).getAsJsonObject(); f.add(new filter(cont.get("field").getAsString(), cont.get("op").getAsString(), cont.get("data").getAsString())); } } filtersArr.put("rules", f); // System.out.println(System.out.printf(searchOperation.get("cn").toString(),"oscar","mesa").toString()); }
From source file:co.edu.uniandes.csw.miso4204.wishlistitem.service._WishListItemService.java
License:MIT License
@GET @Path("validate/{token}") public Long validateUser(@PathParam("token") String token) { String respuesta;//from www . j a v a2 s . c o m String id = "-1"; try { Gson gsonUtil = new Gson(); respuesta = JsonWebToken.decode(token.replace("\"", ""), "Un14nd3s2014@", true); JsonElement jsonPayload = gsonUtil.fromJson(respuesta, JsonElement.class); JsonObject jobjPayload = jsonPayload.getAsJsonObject(); id = (String) jobjPayload.get("id").getAsString(); } catch (Exception ex) { return Long.parseLong("-1"); } return Long.parseLong(id); }
From source file:co.vaughnvernon.tradercommon.media.AbstractJSONMediaReader.java
License:Apache License
protected JsonElement navigateTo(JsonObject aStartingJsonObject, String... aKeys) { if (aKeys.length == 0) { throw new IllegalArgumentException("Must specify one or more keys."); } else if (aKeys.length == 1 && (aKeys[0].startsWith("/") || aKeys[0].contains("."))) { aKeys = this.parsePath(aKeys[0]); }/* w ww . j av a 2 s .c om*/ int keyIndex = 1; JsonElement element = this.elementFrom(aStartingJsonObject, aKeys[0]); if (!element.isJsonNull() && !element.isJsonPrimitive() && !element.isJsonArray()) { JsonObject object = element.getAsJsonObject(); for (; element != null && !element.isJsonPrimitive() && keyIndex < aKeys.length; ++keyIndex) { element = this.elementFrom(object, aKeys[keyIndex]); if (!element.isJsonPrimitive()) { element = this.elementFrom(object, aKeys[keyIndex]); if (element.isJsonNull()) { element = null; } else { object = element.getAsJsonObject(); } } } } if (element != null) { if (!element.isJsonNull()) { if (keyIndex != aKeys.length) { throw new IllegalArgumentException("Last name must reference a simple value."); } } else { element = null; } } return element; }
From source file:cocacola.cocacola.controller.MemberController.java
License:Apache License
public void gerarVideos() throws Exception { CocaCola coca = new CocaCola(); Calendar cal = Calendar.getInstance(); Date date = cal.getTime();//from w ww . ja v a2 s. co m CocaCola c = new CocaCola(cal, "asdasdasdasd", "url1", "Paul", Status.RECEBIDA); ClientRequest request = new ClientRequest( "http://festivaldomeujeito.com.br/server/index.php/festival/user/format/json"); ClientResponse<String> response = request.get(String.class); try { Gson gson = new Gson(); JsonParser parser = new JsonParser(); JsonArray jArray = parser.parse(response.getEntity()).getAsJsonArray(); for (JsonElement obj : jArray) { JsonElement jelem = gson.fromJson(obj, JsonElement.class); JsonObject jobj = jelem.getAsJsonObject(); System.out.println(jobj.get("mon_pergunta_1")); ClasseJsonCoca cocaJson = gson.fromJson(obj, ClasseJsonCoca.class); cocaJson.setMonPergunta1("decarrao"); cocaJson.setUsuGender("female"); c.setJsonCoca(cocaJson); VideoManager vm = new VideoManager(); vm.gerarVideos(c); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:cocacola.cocacola.controller.MemberController.java
License:Apache License
public void testarRestCoca() { try {/*w w w . j a v a2s . c o m*/ Calendar cal = Calendar.getInstance(); Date date = cal.getTime(); CocaCola c = new CocaCola(cal, "asdasdasdasd", "url1", "Paul", Status.RECEBIDA); c.setCor(cocaCola.getCor()); c.setNome(cocaCola.getNome()); c.setSexo(cocaCola.getSexo()); System.out.println(cocaCola.toString()); VideoGerado vg = new VideoGerado(); VideoManager vm = new VideoManager(); ClientRequest request = new ClientRequest( "http://festivaldomeujeito.com.br/server/index.php/festival/user/format/json"); ClientResponse<String> response = request.get(String.class); Gson gson = new Gson(); JsonParser parser = new JsonParser(); JsonArray jArray = parser.parse(response.getEntity()).getAsJsonArray(); for (JsonElement obj : jArray) { System.out.println(obj.toString()); JsonElement jelem = gson.fromJson(obj, JsonElement.class); JsonObject jobj = jelem.getAsJsonObject(); System.out.println(jobj.get("mon_pergunta_1")); ClasseJsonCoca coca = gson.fromJson(obj, ClasseJsonCoca.class); System.out.println(coca.getMonPergunta1()); c.setJsonCoca(coca); vg.setCocaCola(c); System.out.println(vg.getUrlCena2()); System.out.println(vg.getUrlCena3()); System.out.println(vg.getUrlCena4()); System.out.println(vg.getUrlCena5()); System.out.println(vg.getUrlCena6()); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.actimem.blog.gson.immutable.CompanyDeserializer.java
License:Apache License
@Override public Company deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObject = json.getAsJsonObject(); String name = jsonObject.get("name").getAsString(); int foundedYear = jsonObject.get("foundedYear").getAsInt(); double shareValue = jsonObject.get("shareValue").getAsDouble(); return new Company(name, foundedYear, shareValue); }
From source file:com.activiti.client.api.model.deserializer.ResultListDeserializer.java
License:Apache License
@Override public ResultList<T> deserialize(JsonElement je, Type type, JsonDeserializationContext jdc) throws JsonParseException { JsonArray entries = null;//from w w w .j ava 2 s . co m if (je.getAsJsonObject().has(RequestConstant.DATA)) { entries = je.getAsJsonObject().get(RequestConstant.DATA).getAsJsonArray(); } final List<T> result = new ArrayList<>(); T obj = null; if (entries != null) { for (Object entry : entries) { obj = jdc.deserialize((JsonElement) entry, clazz); result.add(obj); } } ResultList<T> resultList = new ResultList<>(); resultList.setList(result); resultList.setSize(je.getAsJsonObject().has(RequestConstant.SIZE) ? je.getAsJsonObject().get(RequestConstant.SIZE).getAsInt() : 0); resultList.setStart(je.getAsJsonObject().has(RequestConstant.START) ? je.getAsJsonObject().get(RequestConstant.START).getAsInt() : 0); resultList.setTotal(je.getAsJsonObject().has(RequestConstant.TOTAL) ? je.getAsJsonObject().get(RequestConstant.TOTAL).getAsInt() : 0); return resultList; }
From source file:com.addthis.hydra.task.source.bundleizer.GsonBundleizer.java
License:Apache License
public ValueObject fromGson(JsonElement gson) { if (gson.isJsonNull()) { return null; } else if (gson.isJsonObject()) { JsonObject object = gson.getAsJsonObject(); ValueMap map = ValueFactory.createMap(); for (Map.Entry<String, JsonElement> entry : object.entrySet()) { map.put(entry.getKey(), fromGson(entry.getValue())); }/*from ww w. ja v a 2 s . c o m*/ return map; } else if (gson.isJsonArray()) { JsonArray gsonArray = gson.getAsJsonArray(); ValueArray valueArray = ValueFactory.createArray(gsonArray.size()); for (JsonElement arrayElement : gsonArray) { valueArray.add(fromGson(arrayElement)); } return valueArray; } else { JsonPrimitive primitive = gson.getAsJsonPrimitive(); if (primitive.isNumber()) { return ValueFactory.create(primitive.getAsDouble()); } else { return ValueFactory.create(primitive.getAsString()); } } }
From source file:com.adkdevelopment.jokesactivity.JokesActivityFragment.java
License:Open Source License
/** * Method to parse JSON string and return String[] with a link and a title * * @param jokesJson JSON string with info about comics, link, etc. * @return String[] with a link and a title *//* w ww. ja v a2 s .c om*/ public static String[] getJokesInfo(String jokesJson) { String[] reviews = new String[2]; JsonParser parser = new JsonParser(); JsonElement element = parser.parse(jokesJson); if (element.isJsonObject()) { JsonObject results = element.getAsJsonObject(); JsonElement title = results.getAsJsonPrimitive("title"); JsonElement linkToImage = results.getAsJsonPrimitive("img"); reviews[0] = title.getAsString(); reviews[1] = linkToImage.getAsString(); return reviews; } return null; }