List of usage examples for com.google.gson JsonParser JsonParser
@Deprecated
public JsonParser()
From source file:com.dangdang.ddframe.job.cloud.scheduler.mesos.fixture.slave.MesosSlaveServerMock.java
License:Apache License
@GET @Path("/state") public JsonObject state() throws JSONException { return (JsonObject) new JsonParser().parse( "{\"version\":\"1.1.0\",\"build_date\":\"2017-02-27 10:51:31\",\"build_time\":1488163891.0,\"build_user\":\"gaohon" + "gtao\",\"start_time\":1488179767.60204,\"id\":\"d8701508-41b7-471e-9b32-61cf824a660d-S0\",\"pid\":\"slave(1)@" + "127.0.0.1:9051\",\"hostname\":\"127.0.0.1\",\"resources\":{\"disk\":416050.0,\"mem\":6883.0,\"gpus\":0.0,\"" + "cpus\":4.0,\"ports\":\"[31000-32000]\"},\"reserved_resources\":{},\"unreserved_resources\":{\"disk\":416050.0,\"" + "mem\":6883.0,\"gpus\":0.0,\"cpus\":4.0,\"ports\":\"[31000-32000]\"},\"reserved_resources_full\":{},\"attributes\"" + ":{},\"master_hostname\":\"127.0.0.1\",\"flags\":{\"appc_simple_discovery_uri_prefix\":\"http:\\/\\/\",\"appc_" + "store_dir\":\"\\/tmp\\/mesos\\/store\\/appc\",\"authenticate_http_readonly\":\"false\",\"authenticate_http_readw" + "rite\":\"false\",\"authenticatee\":\"crammd5\",\"authentication_backoff_factor\":\"1secs\",\"authorizer\":\"local\"" + ",\"cgroups_cpu_enable_pids_and_tids_count\":\"false\",\"cgroups_enable_cfs\":\"false\",\"cgroups_hierarchy\":\"" + "\\/sys\\/fs\\/cgroup\",\"cgroups_limit_swap\":\"false\",\"cgroups_root\":\"mesos\",\"container_disk_watch_interva" + "l\":\"15secs\",\"containerizers\":\"mesos\",\"default_role\":\"*\",\"disk_watch_interval\":\"1mins\",\"docker\":\"dock" + "er\",\"docker_kill_orphans\":\"true\",\"docker_registry\":\"https:\\/\\/registry-1.docker.io\",\"docker_remove_d" + "elay\":\"6hrs\",\"docker_socket\":\"\\/var\\/run\\/docker.sock\",\"docker_stop_timeout\":\"0ns\",\"docker_store_dir" + "\":\"\\/tmp\\/mesos\\/store\\/docker\",\"docker_volume_checkpoint_dir\":\"\\/var\\/run\\/mesos\\/isolators\\/docker" + "\\/volume\",\"enforce_container_disk_quota\":\"false\",\"executor_registration_timeout\":\"1mins\",\"executor_s" + "hutdown_grace_period\":\"5secs\",\"fetcher_cache_dir\":\"\\/tmp\\/mesos\\/fetch\",\"fetcher_cache_size\":\"2GB\",\"" + "frameworks_home\":\"\",\"gc_delay\":\"1weeks\",\"gc_disk_headroom\":\"0.1\",\"hadoop_home\":\"\",\"help\":\"false\",\"ho" + "stname_lookup\":\"true\",\"http_authenticators\":\"basic\",\"http_command_executor\":\"false\",\"image_provision" + "er_backend\":\"copy\",\"initialize_driver_logging\":\"true\",\"ip\":\"127.0.0.1\",\"isolation\":\"cgroups\\/cpu" + ",cgroups\\/mem\",\"launcher\":\"linux\",\"launcher_dir\":\"\\/home\\/gaohongtao\\/mesos\\/mesos-1.1.0\\/build\\/src" + "\",\"logbufsecs\":\"0\",\"logging_level\":\"INFO\",\"master\":\"zk:\\/\\/localhost:4181,\\/mesos\",\"max_completed_ex" + "ecutors_per_framework\":\"150\",\"oversubscribed_resources_interval\":\"15secs\",\"perf_duration\":\"10secs\",\"" + "perf_interval\":\"1mins\",\"port\":\"9051\",\"qos_correction_interval_min\":\"0ns\",\"quiet\":\"false\",\"recover\":\"" + "reconnect\",\"recovery_timeout\":\"15mins\",\"registration_backoff_factor\":\"1secs\",\"revocable_cpu_low_prio" + "rity\":\"true\",\"runtime_dir\":\"\\/var\\/run\\/mesos\",\"sandbox_directory\":\"\\/mnt\\/mesos\\/sandbox\",\"strict\":" + "\"true\",\"switch_user\":\"true\",\"systemd_enable_support\":\"true\",\"systemd_runtime_directory\":\"\\/run\\/syst" + "emd\\/system\",\"version\":\"false\",\"work_dir\":\"\\/home\\/gaohongtao\\/mesos\\/work-1.1.0\"},\"frameworks\":[{\"i" + "d\":\"d8701508-41b7-471e-9b32-61cf824a660d-0000\",\"name\":\"Elastic-Job-Cloud\",\"user\":\"gaohongtao\",\"failo" + "ver_timeout\":604800.0,\"checkpoint\":false,\"role\":\"*\",\"hostname\":\"127.0.0.1\",\"executors\":[{\"id\":\"" + "foo_app@-@d8701508-41b7-471e-9b32-61cf824a660d-S0\",\"name\":\"\",\"source\":\"\",\"container\":\"53fb4af7-aee2-" + "44f6-9e47-6f418d9f27e1\",\"directory\":\"\\/home\\/gaohongtao\\/mesos\\/work-1.1.0\\/slaves\\/d8701508-41b7-47" + "1e-9b32-61cf824a660d-S0\\/frameworks\\/d8701508-41b7-471e-9b32-61cf824a660d-0000\\/executors\\/foo_app@-" + "@d8701508-41b7-471e-9b32-61cf824a660d-S0\\/runs\\/53fb4af7-aee2-44f6-9e47-6f418d9f27e1\",\"resources\":{\"" + "disk\":0.0,\"mem\":512.0,\"gpus\":0.0,\"cpus\":2.5},\"tasks\":[{\"id\":\"cpu_job_1@-@1@-@READY@-@d8701508-41b7-4" + "71e-9b32-61cf824a660d-S0@-@ede114f0-f2db-4bad-b0e0-e820a7d19c59\",\"name\":\"cpu_job_1@-@1@-@READY@-@d87" + "01508-41b7-471e-9b32-61cf824a660d-S0\",\"framework_id\":\"d8701508-41b7-471e-9b32-61cf824a660d-0000\",\"ex" + "ecutor_id\":\"foo_app@-@d8701508-41b7-471e-9b32-61cf824a660d-S0\",\"slave_id\":\"d8701508-41b7-471e-9b32-6" + "1cf824a660d-S0\",\"state\":\"TASK_RUNNING\",\"resources\":{\"disk\":0.0,\"mem\":128.0,\"gpus\":0.0,\"cpus\":0.5},\"s" + "tatuses\":[{\"state\":\"TASK_RUNNING\",\"timestamp\":1488186955.00194,\"container_status\":{\"network_infos\":[" + "{\"ip_addresses\":[{\"ip_address\":\"127.0.0.1\"}]}]}}]},{\"id\":\"cpu_job_1@-@0@-@READY@-@d8701508-41b7-" + "471e-9b32-61cf824a660d-S0@-@31a2862f-c68c-448d-bbcf-8815b5c2dfef\",\"name\":\"cpu_job_1@-@0@-@READY@-@d8" + "701508-41b7-471e-9b32-61cf824a660d-S0\",\"framework_id\":\"d8701508-41b7-471e-9b32-61cf824a660d-0000\",\"e" + "xecutor_id\":\"foo_app@-@d8701508-41b7-471e-9b32-61cf824a660d-S0\",\"slave_id\":\"d8701508-41b7-471e-9b32-" + "61cf824a660d-S0\",\"state\":\"TASK_RUNNING\",\"resources\":{\"disk\":0.0,\"mem\":128.0,\"gpus\":0.0,\"cpus\":0.5},\"" + "statuses\":[{\"state\":\"TASK_RUNNING\",\"timestamp\":1488186955.00214,\"container_status\":{\"network_infos\":" + "[{\"ip_addresses\":[{\"ip_address\":\"127.0.0.1\"}]}]}}]},{\"id\":\"cpu_job_1@-@2@-@READY@-@d8701508-41b7" + "-471e-9b32-61cf824a660d-S0@-@a03017a7-f520-483b-afce-2a5685d0ca2e\",\"name\":\"cpu_job_1@-@2@-@READY@-@d" + "8701508-41b7-471e-9b32-61cf824a660d-S0\",\"framework_id\":\"d8701508-41b7-471e-9b32-61cf824a660d-0000\",\"" + "executor_id\":\"foo_app@-@d8701508-41b7-471e-9b32-61cf824a660d-S0\",\"slave_id\":\"d8701508-41b7-471e-9b32" + "-61cf824a660d-S0\",\"state\":\"TASK_RUNNING\",\"resources\":{\"disk\":0.0,\"mem\":128.0,\"gpus\":0.0,\"cpus\":0.5}," + "\"statuses\":[{\"state\":\"TASK_RUNNING\",\"timestamp\":1488186955.00174,\"container_status\":{\"network_infos\"" + ":[{\"ip_addresses\":[{\"ip_address\":\"127.0.0.1\"}]}]}}]}],\"queued_tasks\":[],\"completed_tasks\":[]}],\"" + "completed_executors\":[]}],\"completed_frameworks\":[]}"); }
From source file:com.dardenestates.code.src.Servlets.JsonServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*w w w .j a v a 2s . c o m*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("application/json"); BufferedReader reader = request.getReader(); List<String> message = new ArrayList(); JsonObject jsonObject; if (reader.ready()) { JsonParser jsonParser = new JsonParser(); try { jsonObject = jsonParser.parse(reader).getAsJsonObject(); } catch (Exception e) { System.out.println(e.getMessage()); System.out.println(e.getStackTrace()); jsonObject = new JsonObject(); jsonObject.add("Exception_Code", new JsonPrimitive("malformed request structure")); } } else { jsonObject = new JsonObject(); jsonObject.add("Exception_Code", new JsonPrimitive("Empty Request")); System.out.println(" Empty Request "); } try (PrintWriter out = response.getWriter()) { out.write(jsonObject.toString()); } //extract the commandkey String commandKey = jsonObject.get("COMMANDKEY").getAsString(); // route the command RoutingEnum routingEnum = RoutingEnum.valueOf(commandKey); ControllerInterface command = routingEnum.getExecutable(); String urlLocation = routingEnum.getResponseURL(); if (command.validate(jsonObject, message, makeDataSource())) { MysqlDataSource dataSource = new MysqlDataSource(); if (command.processRequest(jsonObject, message, dataSource)) { response.sendRedirect(urlLocation); } } //get the value of command //match it with the enum }
From source file:com.davidbracewell.io.structured.json.JSONDocument.java
License:Apache License
@Override public void read(Resource resource) throws StructuredIOException { try {//w w w.ja va 2 s. c o m JsonElement element = new JsonParser().parse(resource.openReader()); setNode(element); } catch (IOException e) { throw new StructuredIOException(e); } }
From source file:com.denimgroup.threadfix.cli.util.JsonTestUtils.java
License:Mozilla Public License
private static <T> JsonObject getJsonObject(RestResponse<T> restResponse) { return new JsonParser().parse(restResponse.getOriginalJson()).getAsJsonObject(); }
From source file:com.devamatre.core.JSONHelper.java
License:Open Source License
/** * //from w ww .j a v a 2s.com * @param jsonString * @return */ public static JsonElement jsonElement(String jsonString) { JsonParser jsonParser = new JsonParser(); return jsonParser.parse(jsonString); }
From source file:com.devamatre.core.JSONHelper.java
License:Open Source License
/** * //w ww. j a v a 2s . c om * @param jsonString * @return */ public static boolean isValidJSONString(String jsonString) { if (jsonString == null) { return false; } else { JsonParser parser = new JsonParser(); try { parser.parse(jsonString); } catch (JsonSyntaxException ex) { return false; } return true; } }
From source file:com.devbliss.doctest.utils.JSONHelper.java
License:Apache License
/** * /*from w w w . j a v a 2 s. c om*/ * Pretty prints any json input. * * @param json * @return */ public String prettyPrintJson(String json) { if (!isJsonValid(json)) { return json; } Gson gson = new GsonBuilder().setPrettyPrinting().create(); JsonParser jp = new JsonParser(); JsonElement je = jp.parse(json); String returnvalue = gson.toJson(je); return returnvalue; }
From source file:com.devnexus.ting.web.controller.AndroidLoginController.java
License:Open Source License
@RequestMapping(path = "/s/user-schedule", method = { RequestMethod.POST, RequestMethod.PUT }) public List<UserScheduleItem> updateUserScheduleCurrentEvent(HttpServletRequest request) { try {/*from ww w .j a v a 2s . c o m*/ String accessToken = request.getHeader("authToken"); User user; user = (User) userService.loadUserByAndroidToken(accessToken); JsonArray presentaitonIds = new JsonParser().parse(request.getReader()).getAsJsonArray(); List<UserScheduleItem> scheduleItems = new ArrayList<>(presentaitonIds.size()); for (int index = 0; index < presentaitonIds.size(); index++) { UserScheduleItem item = new UserScheduleItem(); item.setUser(user); item.setScheduleItem( businessService.getPresentation(presentaitonIds.get(index).getAsLong()).getScheduleItem()); scheduleItems.add(item); } calendarServices.replaceScheduleItemsForUser(user, scheduleItems); return businessService.getUserScheduleItemsForCurrentEventForUser(user); } catch (IOException ex) { Logger.getLogger(AndroidLoginController.class.getName()).log(Level.SEVERE, null, ex); throw new RuntimeException(ex); } }
From source file:com.devonfw.module.i18n.common.util.I18nUtils.java
License:Apache License
/** * @param resourceMap contains the resources in the form of key value pairs * @param filter received from service//from w w w. j a v a2 s. c o m * @return resources as JSON String * @throws Throwable thrown by getResourcesAsJSON */ public static String getResourcesAsJSON(HashMap<String, String> resourceMap, String filter) throws Throwable { JsonParser jsonParser = new JsonParser(); final java.lang.reflect.Type mapType = new TypeToken<Map<String, String>>() { }.getType(); String strJSON = new GsonBuilder().registerTypeAdapter(mapType, new BundleMapSerializer()).create() .toJson(resourceMap, mapType); if (filter != null && !filter.isEmpty()) { JsonObject obj = (JsonObject) jsonParser.parse(strJSON); strJSON = I18nUtils.getJsonObj(obj, filter); } return strJSON; }
From source file:com.dict.crawl.NewsNationalGeographicCrawler.java
License:Open Source License
public static void main(String[] args) throws Exception { /*string,crawlPath??crawlPath, ????crawlPath/*from ww w.j a v a 2 s. c o m*/ */ NewsNationalGeographicCrawler crawler = new NewsNationalGeographicCrawler("data/NewsNationalGeographic"); crawler.setThreads(2); crawler.addSeed("http://ngm.nationalgeographic.com/"); if (BaseCrawler.isNormalTime()) { crawler.addSeed("http://ngm.nationalgeographic.com/archives"); crawler.addSeed("http://ngm.nationalgeographic.com/featurehub"); // //} String jsonUrl = "http://news.nationalgeographic.com/bin/services/news/public/query/content.json?pageSize=20&page=0&contentTypes=news/components/pagetypes/article,news/components/pagetypes/simple-article,news/components/pagetypes/photo-gallery"; URL urls = new URL(jsonUrl); HttpURLConnection urlConnection = (HttpURLConnection) urls.openConnection(); InputStream is = urlConnection.getInputStream(); Reader rd = new InputStreamReader(is, "utf-8"); JsonArray json = new JsonParser().parse(rd).getAsJsonArray(); for (JsonElement jOb : json) { String url = jOb.getAsJsonObject().get("page").getAsJsonObject().get("url").getAsString(); if (url != null && !url.equals("")) crawler.addSeed(url); } } // crawler.addSeed("http://news.nationalgeographic.com/2016/01/160118-mummies-world-bog-egypt-science/"); // List<Map<String, Object>> urls = crawler.jdbcTemplate.queryForList("SELECT id,title,url FROM parser_page where host like '%news.national%' ORDER by id desc;"); // for(int i = 0; i < urls.size(); i++) { // String url = (String) urls.get(i).get("url"); // String title = (String) urls.get(i).get("title"); //// int id = (int) urls.get(i).get("id"); // crawler.addSeed(url); // } // Config Config.WAIT_THREAD_END_TIME = 1000 * 60 * 5;//???kill // Config.TIMEOUT_CONNECT = 1000*10; // Config.TIMEOUT_READ = 1000*30; Config.requestMaxInterval = 1000 * 60 * 20;//??-?>hung //requester??http??requester?http/socks? HttpRequesterImpl requester = (HttpRequesterImpl) crawler.getHttpRequester(); AntiAntiSpiderHelper.defaultUserAgent(requester); // requester.setUserAgent("Mozilla/5.0 (X11; Linux i686; rv:33.0) Gecko/20100101 Firefox/33.0"); // requester.setCookie("CNZZDATA1950488=cnzz_eid%3D739324831-1432460954-null%26ntime%3D1432460954; wdcid=44349d3f2aa96e51; vjuids=-53d395da8.14eca7eed44.0.f17be67e; CNZZDATA3473518=cnzz_eid%3D1882396923-1437965756-%26ntime%3D1440635510; pt_37a49e8b=uid=FuI4KYEfVz5xq7L4nzPd1w&nid=1&vid=r4AhSBmxisCiyeolr3V2Ow&vn=1&pvn=1&sact=1440639037916&to_flag=0&pl=t4NrgYqSK5M357L2nGEQCw*pt*1440639015734; _ga=GA1.3.1121158748.1437970841; __auc=c00a6ac114d85945f01d9c30128; CNZZDATA1975683=cnzz_eid%3D250014133-1432460541-null%26ntime%3D1440733997; CNZZDATA1254041250=2000695407-1442220871-%7C1442306691; pt_7f0a67e8=uid=6lmgYeZ3/jSObRMeK-t27A&nid=0&vid=lEKvEtZyZdd0UC264UyZnQ&vn=2&pvn=1&sact=1442306703728&to_flag=0&pl=7GB3sYS/PJDo1mY0qeu2cA*pt*1442306703728; 7NSx_98ef_saltkey=P05gN8zn; 7NSx_98ef_lastvisit=1444281282; IframeBodyHeight=256; NTVq_98ef_saltkey=j5PydYru; NTVq_98ef_lastvisit=1444282735; NTVq_98ef_atarget=1; NTVq_98ef_lastact=1444286377%09api.php%09js; 7NSx_98ef_sid=hZyDwc; __utmt=1; __utma=155578217.1121158748.1437970841.1443159326.1444285109.23; __utmb=155578217.57.10.1444285109; __utmc=155578217; __utmz=155578217.1439345650.3.2.utmcsr=travel.chinadaily.com.cn|utmccn=(referral)|utmcmd=referral|utmcct=/; CNZZDATA3089622=cnzz_eid%3D1722311508-1437912344-%26ntime%3D1444286009; wdlast=1444287704; vjlast=1437916393.1444285111.11; 7NSx_98ef_lastact=1444287477%09api.php%09chinadaily; pt_s_3bfec6ad=vt=1444287704638&cad=; pt_3bfec6ad=uid=bo87MAT/HC3hy12HDkBg1A&nid=0&vid=erwHQyFKxvwHXYc4-r6n-w&vn=28&pvn=2&sact=1444287708079&to_flag=0&pl=kkgvLoEHXsCD2gs4VJaWQg*pt*1444287704638; pt_t_3bfec6ad=?id=3bfec6ad.bo87MAT/HC3hy12HDkBg1A.erwHQyFKxvwHXYc4-r6n-w.kkgvLoEHXsCD2gs4VJaWQg.nZJ9Aj/bgfNDIKBXI5TwRQ&stat=167.132.1050.1076.1body%20div%3Aeq%288%29%20ul%3Aeq%280%29%20a%3Aeq%282%29.0.0.1595.3441.146.118&ptif=4"); //?? Mozilla/5.0 (X11; Linux i686; rv:34.0) Gecko/20100101 Firefox/34.0 //c requester.setProxy(" /* //?? RandomProxyGenerator proxyGenerator=new RandomProxyGenerator(); proxyGenerator.addProxy("127.0.0.1",8080,Proxy.Type.SOCKS); requester.setProxyGenerator(proxyGenerator); */ /*??*/ // crawler.setResumable(true); crawler.setResumable(false); crawler.start(2); }