List of usage examples for com.google.gson JsonParser JsonParser
@Deprecated
public JsonParser()
From source file:co.edu.uniandes.csw.miso4204.reward.service.RewardService.java
License:MIT License
@POST @Path("/save") public RewardDTO saveReward(@Context HttpHeaders httpHeaders, RewardDTO reward) { try {//from w w w .j a va 2 s. c om String path = new File(".").getCanonicalPath(); } catch (Exception e) { } String token = httpHeaders.getRequestHeader("X_REST_USER").get(0); ClientConfig config = new ClientConfig(); Client client = ClientBuilder.newClient(config); String entity = client.target(URL_SERVICIO).path(reward.getBuyerId().toString()) .request(MediaType.APPLICATION_JSON).header("X_REST_USER", token).get(String.class); System.out.println(entity); JsonParser parser = new JsonParser(); JsonObject object = (JsonObject) parser.parse(entity); JsonElement column = object.get("id"); String id = column.getAsString(); System.out.println(id); reward.setBuyerId(Long.parseLong(id)); createReward(reward); return reward; }
From source file:co.mitro.keyczar.KeyczarJsonReader.java
License:Open Source License
public KeyczarJsonReader(String json) { JsonParser parser = new JsonParser(); parsed = parser.parse(json).getAsJsonObject(); }
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();/* w ww . ja va 2 s. c om*/ 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 {/*from w w w . j av a 2s .c om*/ 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.addthis.hydra.task.source.bundleizer.GsonBundleizer.java
License:Apache License
@Override public Bundleizer createBundleizer(final InputStream inputArg, final BundleFactory factoryArg) { return new Bundleizer() { private final BundleFactory factory = factoryArg; private final JsonParser parser = new JsonParser(); private final JsonReader reader = new JsonReader(new BufferedReader(new InputStreamReader(inputArg))); {// ww w .java 2 s.co m try { reader.beginArray(); } catch (IOException e) { throw new RuntimeException(e); } } @Override public Bundle next() throws IOException { if (reader.hasNext()) { JsonObject nextElement = parser.parse(reader).getAsJsonObject(); Bundle next = factory.createBundle(); BundleFormat format = next.getFormat(); for (Map.Entry<String, JsonElement> entry : nextElement.entrySet()) { next.setValue(format.getField(entry.getKey()), fromGson(entry.getValue())); } return next; } else { return null; } } }; }
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 w w. jav a 2 s . c o m*/ 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; }
From source file:com.adobe.acs.commons.adobeio.service.impl.EndpointServiceImpl.java
License:Apache License
private JsonObject responseAsJson(@NotNull final HttpResponse response) throws IOException { String result = IOUtils.toString(response.getEntity().getContent(), CharEncoding.UTF_8); JsonParser parser = new JsonParser(); JsonObject resultJson = new JsonObject(); try {/*from w ww . java2s . co m*/ LOGGER.debug("Call result = {}", result); resultJson = parser.parse(result).getAsJsonObject(); } catch (Exception e) { resultJson.addProperty(RESULT_ERROR, result); } LOGGER.debug("JSON result from Service: {}", resultJson); return resultJson; }
From source file:com.adobe.acs.commons.adobeio.service.impl.IntegrationServiceImpl.java
License:Apache License
private String fetchAccessToken() { String token = StringUtils.EMPTY; try (CloseableHttpClient client = helper.getHttpClient(getTimeoutinMilliSeconds())) { HttpPost post = new HttpPost(jwtServiceConfig.endpoint()); post.addHeader(CACHE_CONTRL, NO_CACHE); post.addHeader(CONTENT_TYPE, CONTENT_TYPE_URL_ENCODED); List<BasicNameValuePair> params = Lists.newArrayList(); params.add(new BasicNameValuePair(CLIENT_ID, jwtServiceConfig.clientId())); params.add(new BasicNameValuePair(CLIENT_SECRET, jwtServiceConfig.clientSecret())); params.add(new BasicNameValuePair(JWT_TOKEN, getJwtToken())); post.setEntity(new UrlEncodedFormEntity(params)); HttpResponse response = client.execute(post); if (response.getStatusLine().getStatusCode() != 200) { LOGGER.info("response code {} ", response.getStatusLine().getStatusCode()); }//from ww w .j a va 2 s . co m String result = IOUtils.toString(response.getEntity().getContent(), "UTF-8"); LOGGER.info("JSON Response : {}", result); JsonParser parser = new JsonParser(); JsonObject json = parser.parse(result).getAsJsonObject(); if (json.has(JSON_ACCESS_TOKEN)) { token = json.get(JSON_ACCESS_TOKEN).getAsString(); } else { LOGGER.error("JSON does not contain an access_token"); } } catch (Exception e) { LOGGER.error(e.getMessage()); } LOGGER.info("JWT Access Token : {}", token); return token; }
From source file:com.adobe.acs.commons.exporters.impl.users.Parameters.java
License:Apache License
public Parameters(SlingHttpServletRequest request) throws IOException { final JsonObject json = new JsonParser().parse(request.getParameter("params")).getAsJsonObject(); final List<String> tmpCustomProperties = new ArrayList<String>(); final List<String> tmpGroups = new ArrayList<String>(); groupFilter = getString(json, GROUP_FILTER); JsonArray groupsJSON = json.getAsJsonArray(GROUPS); for (int i = 0; i < groupsJSON.size(); i++) { tmpGroups.add(groupsJSON.get(i).getAsString()); }/* w ww. j a va 2s. co m*/ this.groups = tmpGroups.toArray(new String[tmpGroups.size()]); JsonArray customPropertiesJSON = json.getAsJsonArray(CUSTOM_PROPERTIES); for (int i = 0; i < customPropertiesJSON.size(); i++) { JsonObject tmp = customPropertiesJSON.get(i).getAsJsonObject(); if (tmp.has(RELATIVE_PROPERTY_PATH)) { String relativePropertyPath = getString(tmp, RELATIVE_PROPERTY_PATH); tmpCustomProperties.add(relativePropertyPath); } } this.customProperties = tmpCustomProperties.toArray(new String[tmpCustomProperties.size()]); }
From source file:com.adobe.acs.commons.json.JsonObjectUtil.java
License:Apache License
public static JsonObject toJsonObject(String json) { JsonParser parse = new JsonParser(); return parse.parse(json).getAsJsonObject(); }