@SuppressWarnings("unchecked") @Override public String toJSONString() { JSONArray jsonArray = new JSONArray(); for(String kw : keywords) { JSONObject data = new JSONObject(); data.put("name", kw); data.put("value", kw); jsonArray.add(data); } return jsonArray.toJSONString(); }
public static void process(Reader in) { JSONParser parser = new JSONParser(); try { Object o = parser.parse(in); if (o instanceof JSONArray) { JSONArray jsonArray = (JSONArray) o; for (int i = 0; i <jsonArray.size(); i++) { Object element = jsonArray.get(i); if (element instanceof JSONObject) { process((JSONObject) element); } } } else if (o instanceof JSONObject) { process((JSONObject) o); } else { scouter.server.Logger.println("SC-8001", 30, "Incorrect body"); } } catch(Throwable th) { scouter.server.Logger.println("SC-8000", 30, "Http body parsing error", th); } }
JSONArray acls = (JSONArray) ((JSONObject) new JSONParser().parse(jsonAcl)).get("acls"); for (Iterator it = acls.iterator(); it.hasNext();) { JSONObject acl = (JSONObject) it.next(); String scheme = ((String) acl.get("scheme")).trim(); String id = ((String) acl.get("id")).trim(); int perms = 0; String permStr = ((String) acl.get("perms")).toLowerCase().trim();
private boolean compareArraysByStrictOrder(JSONArray expected, JSONArray actual) { if (expected.size() != actual.size()) { return false; } for (int index = 0; index < expected.size(); index++) { Object expectedElt = expected.get(index); Object actualElt = actual.get(index); if (!compare(expectedElt, actualElt)) { return false; } } return true; }
@SuppressWarnings( "unchecked" ) private String buildJsonQueryResult( QueryResult queryResult ) throws KettleException { JSONArray list = new JSONArray(); for ( SObject sobject : queryResult.getRecords() ) { list.add( buildJSONSObject( sobject ) ); } StringWriter sw = new StringWriter(); try { list.writeJSONString( sw ); } catch ( IOException e ) { throw new KettleException( e ); } return sw.toString(); }
@Override protected List<WorkflowJob> call(HttpURLConnection conn) throws IOException, OozieClientException { if ((conn.getResponseCode() == HttpURLConnection.HTTP_OK)) { Reader reader = new InputStreamReader(conn.getInputStream(), Charsets.UTF_8); JSONObject json = (JSONObject) JSONValue.parse(reader); JSONArray workflows = (JSONArray) json.get(JsonTags.WORKFLOWS_JOBS); if (workflows == null) { workflows = new JSONArray(); } return JsonToBean.createWorkflowJobList(workflows); } else { handleError(conn); } return null; } }
@Override public Void call() throws Exception { MockDagEngineService.reset(); Map<String, String> params = new HashMap<String, String>(); params.put(RestConstants.JOBTYPE_PARAM, "bundle"); params.put(RestConstants.JOBS_FILTER_PARAM, OozieClient.FILTER_STATUS + "=PREP;" + OozieClient.FILTER_NAME + "=BUNDLE-TEST;" + OozieClient.FILTER_USER + "=" + getTestUser()); URL url = createURL("", params); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); assertEquals(HttpServletResponse.SC_OK, conn.getResponseCode()); assertTrue(conn.getHeaderField("content-type").startsWith(RestConstants.JSON_CONTENT_TYPE)); JSONObject json = (JSONObject) JSONValue.parse(new InputStreamReader(conn.getInputStream())); assertEquals(Long.valueOf(1L), json.get("total")); JSONArray array = (JSONArray) json.get("bundlejobs"); JSONObject jo = (JSONObject) array.get(0); assertEquals(bundleJobBean.getId(), jo.get("bundleJobId")); return null; } });
public Void call() throws Exception { Map<String, String> params = new HashMap<String, String>(); URL url = createURL("", params); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); assertEquals(HttpServletResponse.SC_OK, conn.getResponseCode()); assertTrue(conn.getHeaderField("content-type").startsWith(RestConstants.JSON_CONTENT_TYPE)); JSONArray array = (JSONArray) JSONValue.parse(new InputStreamReader(conn.getInputStream())); assertEquals(3, array.size()); assertEquals(OozieClient.WS_PROTOCOL_VERSION_1, array.get(1)); return null; } });
public Map<String, UUID> call() throws Exception { Map<String, UUID> uuidMap = new HashMap<String, UUID>(); int requests = (int) Math.ceil(names.size() / PROFILES_PER_REQUEST); for (int i = 0; i < requests; i++) { HttpURLConnection connection = createConnection(); String body = JSONArray.toJSONString(names.subList(i * PROFILES_PER_REQUEST, Math.min((i + 1) * PROFILES_PER_REQUEST, names.size()))); writeBody(connection, body); JSONArray array = (JSONArray) jsonParser.parse(new InputStreamReader(connection.getInputStream())); for (Object profile : array) { JSONObject jsonProfile = (JSONObject) profile; String id = (String) jsonProfile.get("id"); String name = (String) jsonProfile.get("name"); UUID uuid = UUIDFetcher.getUUID(id); uuidMap.put(name, uuid); } if (rateLimiting && i != requests - 1) { Thread.sleep(RATE_LIMIT); } } return uuidMap; }
os.writeBytes(JSONValue.toJSONString(playerList)); json = (JSONArray) JSONValue.parse(new InputStreamReader(conn.getInputStream())); } catch (IOException e) { GlowServer.logger.warning("Couldn't get UUID due to IO error: " + e); if (!json.isEmpty()) { String uuid = (String) ((JSONObject) json.get(0)).get("id"); return UuidUtils.fromFlatString(uuid);
public static CardsList create() throws Exception { CardsList instance = new CardsList(); JSONParser parser = new JSONParser(); Reader reader = new BufferedReader( new InputStreamReader(CardsList.class.getResourceAsStream("cards.json"), "UTF-8")); String cardsString = ((org.json.simple.JSONArray) parser.parse(reader)).toJSONString(); ObjectMapper mapper = new ObjectMapper(); instance.dbCards = mapper.readValue(cardsString, TypeFactory.defaultInstance().constructCollectionType(List.class, DbCard.class)); return instance; }
public JSONArray storeRecentSearch( String recentSearch ) { JSONArray recentSearches = getRecentSearches(); try { if ( recentSearch == null || recentSearches.contains( recentSearch ) ) { return recentSearches; } recentSearches.add( recentSearch ); if ( recentSearches.size() > 5 ) { recentSearches.remove( 0 ); } PropsUI props = PropsUI.getInstance(); String jsonValue = props.getRecentSearches(); JSONParser jsonParser = new JSONParser(); JSONObject jsonObject = jsonValue != null ? (JSONObject) jsonParser.parse( jsonValue ) : new JSONObject(); jsonObject.put( getLogin(), recentSearches ); props.setRecentSearches( jsonObject.toJSONString() ); } catch ( Exception e ) { e.printStackTrace(); } return recentSearches; }
public JSONArray getRecentSearches() { try { PropsUI props = PropsUI.getInstance(); String jsonString = props.getRecentSearches(); if ( jsonString != null ) { JSONParser jsonParser = new JSONParser(); JSONObject jsonObject = (JSONObject) jsonParser.parse( jsonString ); return (JSONArray) jsonObject.get( getLogin() ); } } catch ( Exception e ) { // Log error in console } return new JSONArray(); }
public void add(NotificationDescriptor notificationDescriptor) { JSONParser parser = new JSONParser(); try { JSONObject root = (JSONObject) parser.parse(new FileReader(HISTORY_FILE)); JSONArray msgsArray = (JSONArray) root.get("messages"); msgsArray.add(0, notificationDescriptor.getSourceString()); root.replace("messages", msgsArray); FileWriter fileWriter = new FileWriter(HISTORY_FILE); fileWriter.write(root.toJSONString()); fileWriter.flush(); fileWriter.close(); } catch (Exception e) { logger.error("Error during adding message to history file: ", e); } }
private JSONArray getDeviceIdsFromDevices(JSONArray devices) { JSONArray deviceIdentifiers = new JSONArray(); Iterator<JSONObject> iterator = devices.iterator(); while (iterator.hasNext()) { JSONObject deviceObj = iterator.next(); JSONObject obj = new JSONObject(); obj.put(Constants.ID, deviceObj.get(Constants.DEVICE_IDENTIFIER).toString()); obj.put(Constants.TYPE, deviceObj.get(Constants.TYPE).toString()); deviceIdentifiers.add(obj); } return deviceIdentifiers; }
@Test @SuppressWarnings("unchecked") public void testPatchNotAllowedAlert() throws ParseException { PatchRequest pr = new PatchRequest(); Map<String, Object> patch = (JSONObject) new JSONParser().parse(alertPatchRequest); pr.setPatch(Collections.singletonList((JSONObject) ((JSONArray) patch.get("patch")).get(0))); assertFalse(dao.isPatchAllowed(pr)); }
private static PerfCounterPack extractPerfCounterPack(JSONArray perfJson, String objName) { PerfCounterPack perfPack = new PerfCounterPack(); perfPack.time = System.currentTimeMillis(); perfPack.timetype = TimeTypeEnum.REALTIME; perfPack.objName = objName; for (int i = 0; i < perfJson.size(); i++) { JSONObject perf = (JSONObject) perfJson.get(i); String name = (String) perf.get("name"); Number value = (Number) perf.get("value"); perfPack.data.put(name, new FloatValue(value.floatValue())); } return perfPack; }
@SuppressWarnings("unchecked") @Override public boolean parseVertex(LongWritable key, Text value, Vertex<Text, NullWritable, DoubleWritable> vertex) throws Exception { JSONArray jsonArray = (JSONArray) new JSONParser() .parse(value.toString()); vertex.setVertexID(new Text(jsonArray.get(0).toString())); Iterator<JSONArray> iter = ((JSONArray) jsonArray.get(2)).iterator(); while (iter.hasNext()) { JSONArray edge = (JSONArray) iter.next(); vertex.addEdge(new Edge<Text, NullWritable>(new Text(edge.get(0) .toString()), null)); } return true; } }
JSONObject envJSON = (JSONObject) testCaseJSONObj.get("env"); JSONObject execJSON = (JSONObject) testCaseJSONObj.get("exec"); JSONObject preJSON = (JSONObject) testCaseJSONObj.get("pre"); JSONObject postJSON = new JSONObject(); if (testCaseJSONObj.containsKey("post")) { postJSON = (JSONObject) testCaseJSONObj.get("post"); JSONArray callCreates = new JSONArray(); if (testCaseJSONObj.containsKey("callcreates")) callCreates = (JSONArray) testCaseJSONObj.get("callcreates"); Object logsJSON = new JSONArray(); if (testCaseJSONObj.containsKey("logs")) logsJSON = testCaseJSONObj.get("logs");
@SuppressWarnings( "unchecked" ) private void outPutRow( Object[] rowData ) throws KettleStepException { // We can now output an object data.jg = new JSONObject(); data.jg.put( data.realBlocName, data.ja ); String value = data.jg.toJSONString(); if ( data.outputValue && data.outputRowMeta != null ) { Object[] outputRowData = RowDataUtil.addValueData( rowData, data.inputRowMetaSize, value ); incrementLinesOutput(); putRow( data.outputRowMeta, outputRowData ); } if ( data.writeToFile && !data.ja.isEmpty() ) { // Open a file if ( !openNewFile() ) { throw new KettleStepException( BaseMessages.getString( PKG, "JsonOutput.Error.OpenNewFile", buildFilename() ) ); } // Write data to file try { data.writer.write( value ); } catch ( Exception e ) { throw new KettleStepException( BaseMessages.getString( PKG, "JsonOutput.Error.Writing" ), e ); } // Close file closeFile(); } // Data are safe data.rowsAreSafe = true; data.ja = new JSONArray(); }