Refine search
JSONParser parser = new JSONParser(); JSONObject testSuiteObj = null; testSuiteObj = (JSONObject) parser.parse(result); JSONArray tree = (JSONArray)testSuiteObj.get("tree"); String type = (String) entry.get("type"); String path = (String) entry.get("path"); e.printStackTrace();
private void formatResponse(String result) { JSONParser parser = new JSONParser(); Object status; try { status = parser.parse(result); } catch (ParseException e) { System.err.println("Invalid response received from AM"); if (opts.verbose) { System.out.println(result); System.out.println(e.getMessage()); } return; } JSONObject root = (JSONObject) status; showMetric("AM State", root, "state"); showMetric("Target Drillbit Count", root.get("summary"), "targetBitCount"); showMetric("Live Drillbit Count", root.get("summary"), "liveBitCount"); showMetric("Unmanaged Drillbit Count", root.get("summary"), "unmanagedCount"); showMetric("Blacklisted Node Count", root.get("summary"), "blackListCount"); showMetric("Free Node Count", root.get("summary"), "freeNodeCount"); }
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")) { throw new ParseException(0, e);
/** * Convenience method that JSON Parses the <code>InputStream</code> of a * <code>HttpURLConnection</code>. * * @param conn the <code>HttpURLConnection</code>. * * @return the parsed JSON object. * * @throws IOException thrown if the <code>InputStream</code> could not be * JSON parsed. */ static Object jsonParse(HttpURLConnection conn) throws IOException { try { JSONParser parser = new JSONParser(); return parser.parse( new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8)); } catch (ParseException ex) { throw new IOException("JSON parser error, " + ex.getMessage(), ex); } } }
static Map<String, Double> parseResources(String input) { Map<String, Double> topologyResources = new HashMap<>(); JSONParser parser = new JSONParser(); LOG.debug("Input to parseResources {}", input); try { if (input != null) { Object obj = parser.parse(input); JSONObject jsonObject = (JSONObject) obj; if (jsonObject.containsKey(Config.TOPOLOGY_COMPONENT_RESOURCES_ONHEAP_MEMORY_MB)) { Double topoMemOnHeap = ObjectReader .getDouble(jsonObject.get(Config.TOPOLOGY_COMPONENT_RESOURCES_ONHEAP_MEMORY_MB), null); topologyResources.put(Config.TOPOLOGY_COMPONENT_RESOURCES_ONHEAP_MEMORY_MB, topoMemOnHeap); if (jsonObject.containsKey(Config.TOPOLOGY_COMPONENT_RESOURCES_OFFHEAP_MEMORY_MB)) { Double topoMemOffHeap = ObjectReader .getDouble(jsonObject.get(Config.TOPOLOGY_COMPONENT_RESOURCES_OFFHEAP_MEMORY_MB), null); LOG.error("Failed to parse component resources is:" + e.toString(), e); return null;
private void handleParameters(Event event, List<Parm> parameters, JSONObject body) { final JSONParser jsonParser = new JSONParser(); for(Parm parm : parameters) { final String parmName = "p_" + parm.getParmName().replaceAll("\\.", "_"); // Some parameter values are of type json and should be decoded properly. // See HZN-1272 if ("json".equalsIgnoreCase(parm.getValue().getType())) { try { JSONObject tmpJson = (JSONObject) jsonParser.parse(parm.getValue().getContent()); body.put(parmName, tmpJson); } catch (ParseException ex) { LOG.error("Cannot parse parameter content '{}' of parameter '{}' from eventid {} to json: {}", parm.getValue().getContent(), parm.getParmName(), event.getDbid(), ex.getMessage(), ex); // To not lose the data, just use as is body.put(parmName, parm.getValue().getContent()); } } else { body.put(parmName, parm.getValue().getContent()); } } }
/** * Parses the specified JSON string and ensures it is a JSONObject. * * @param jwt The string to parse * @return The parsed JSON object on success * @throws ParseException Thrown if the given JSON string is invalid or does not start with a JSONObject */ private JSONObject parseJwtString( String jwt ) throws ParseException { Object jsonParsed = new JSONParser().parse( jwt ); if ( jsonParsed instanceof JSONObject ) { return (JSONObject) jsonParsed; } else { throw new ParseException( ParseException.ERROR_UNEXPECTED_TOKEN ); } }
requestJSONObject = new JSONParser().parse(request.getReader()); if ((requestJSONObject == null) || !(requestJSONObject instanceof JSONObject)) " could not parse JSON, message: %s", pe.getMessage()); logger.error(message); response.getOutputStream().println(message); responseJSONObject = new JSONObject(); responseJSONObject.writeJSONString( response.getWriter());
@Before public void parseMessages() { JSONParser parser = new JSONParser(); try { joinedMessage = (JSONObject) parser.parse(joinedMessageString); } catch (ParseException e) { e.printStackTrace(); } joinBolt = new StandAloneJoinBolt("zookeeperUrl"); joinBolt.setCuratorFramework(client); joinBolt.setZKCache(cache); }
public Object parse(String s, ContainerFactory containerFactory) throws ParseException{ StringReader in=new StringReader(s); try{ return parse(in, containerFactory); } catch(IOException ie){ /* * Actually it will never happen. */ throw new ParseException(-1, ParseException.ERROR_UNEXPECTED_EXCEPTION, ie); } }
JSONObject jsonObject = (JSONObject) jsonParser.parse(textData); String type = (String) jsonObject.get("type"); if (type.equals(CHAT_TYPE)) { ChatMessage chatMessage = gson.fromJson(textData, ChatMessage.class); e.printStackTrace();
JsonNode objectJsonNodeData = null; try { objectJsonNodeData = mapper.readTree(objectMetadata.toJSONString()); } catch (IOException e) { logger.log(Level.SEVERE, e.getMessage()); objectMetadata = (JSONObject) parser.parse(objectJsonNodeData.toString()); } catch (ParseException e1) { e1.printStackTrace(); try { String stringRepOfMappedNode = mapper.writeValueAsString(nodeModelDef); nodeDef = ((JSONObject) parser.parse(stringRepOfMappedNode)); } catch (JsonProcessingException e) { logger.log(Level.SEVERE, e.getMessage()); } catch (ParseException e) { logger.log(Level.SEVERE, e.getMessage()); nodeDef = (JSONObject) modelProperties.get(nodeName);
@NotNull protected Map parseJson() throws ComponentInitException { JSONObject ret = new JSONObject(); JSONParser parser = new JSONParser(); Object parse = null; try { parse = parser.parse(new InputStreamReader(inputStream), new InsertionOrderedContainerFactory()); } catch (org.json.simple.parser.ParseException e) { throw new ComponentInitException(e.toString(), e); } catch (IOException e) { throw new ComponentInitException(e); } logger.trace("parse was: " + parse.toString()); if (!(parse instanceof Map)) { throw new ComponentInitException("Not a JSON object: " + parse.getClass()); } return (Map) parse; }
@Override public void create(IdentityRequest.IdentityRequestBuilder builder, HttpServletRequest request, HttpServletResponse response) throws FrameworkClientException { RegistrationRequest.RegistrationRequestBuilder registerRequestBuilder; if (builder instanceof RegistrationRequest.RegistrationRequestBuilder) { registerRequestBuilder = (RegistrationRequest.RegistrationRequestBuilder) builder; super.create(registerRequestBuilder, request, response); try { Reader requestBodyReader = request.getReader(); JSONParser jsonParser = new JSONParser(); JSONObject jsonData = (JSONObject) jsonParser.parse(requestBodyReader); if (log.isDebugEnabled()) { log.debug("DCR request json : " + jsonData.toJSONString()); } parseJson(jsonData, registerRequestBuilder); } catch (IOException e) { String errorMessage = "Error occurred while reading servlet request body, " + e.getMessage(); FrameworkClientException.error(errorMessage, e); } catch (ParseException e) { String errorMessage = "Error occurred while parsing the json object, " + e.getMessage(); FrameworkClientException.error(errorMessage, e); } } }
for(Object o: ja) { JSONObject jo = (JSONObject) o; JSONObject status = new JSONObject(); try { putDocument(api, jo); status.put("added", true); } catch(Exception e) { status.put("added", false); status.put("error", "Invalid or missing argument"); // TODO: descriptive error msg hasError = true; if(LOG_ENABLED) LOG.severe("PUT doc, parse input " + e.getMessage()); } catch (ParseException e) { if(LOG_ENABLED) LOG.severe("PUT doc, parse input " + e.getMessage()); } catch (Exception e) { if(LOG_ENABLED) LOG.severe("PUT doc " + e.getMessage());
@Override public boolean nextKeyValue() throws IOException, InterruptedException { boolean next = lineRecordReader.nextKeyValue(); if (next) { String line = lineRecordReader.getCurrentValue().toString(); try { JSONObject json = (JSONObject) parser.parse(line); String author = (String) json.get("author"); String link = (String) json.get("link"); } catch (ParseException e) { if (skipBadLines) { System.err.println("Bad line at offset: " + lineRecordReader.getCurrentKey().get() + ":\n" + e.getMessage()); badLineCount++; } else { throw new IOException(e); } } } return next; }
@Override protected void map(LongWritable offset, Text value, Context context) throws IOException, InterruptedException { String line = value.toString(); try { Object o = parser.parse(line); } catch (ParseException e) { if (skipBadLines) { System.err.println("Bad line at offset: " + offset.get() + ":\n" + e.getMessage()); badLineCount.increment(1); return; } else { throw new IOException(e); } } } }
/** * access the status update loaded<br> * (calls will cause an exception if you did not successfully load one * before) * * @return status update loaded before */ @SuppressWarnings("unchecked") public JSONObject getStatusUpdate() { JSONObject statusUpdate = null; try { statusUpdate = (JSONObject) JSON_PARSER .parse((String) this.nextStatusUpdateNode .getProperty(Properties.StatusUpdate.CONTENT)); } catch (final ParseException e) { e.printStackTrace(); } // (create and) add user object if (this.userJSON == null) { final User user = new User(this.userNode); this.userJSON = user.toActorJSON(); } statusUpdate.put("actor", this.userJSON); this.nextStatusUpdate(); return statusUpdate; }
json = parseJwtString( jwt ); } catch ( ParseException e ) { e.printStackTrace(); return; Object jsonChainRaw = json.get( "chain" ); if ( !( jsonChainRaw instanceof JSONArray ) ) { return;
/** * Builds a JSON Object instance which conforms to the specifications of the model and other * settings of this class such as useRequiredOnly. * * @return Object JSON Object of model type */ public Object buildValidModelInstance() { if (modelType == ModelPropertyType.OBJECT) { if (presetNodes != null && objectMetadata.isEmpty()) { objectMetadata = presetNodes; } if (nodesToBuild != null) { return buildTargetedNodes(); } else { JSONObject modelSet = (requiredOnly) ? getRequiredOnlyDefs(model) : modelProperties; return buildModelInstance(modelSet); } } else { try { ArrayNode generatedItems = buildArrayNode(model); String itemsString = generatedItems.toString(); objectItems = (JSONArray) (parser.parse(itemsString)); } catch (ParseException e) { logger.log(Level.SEVERE, e.getMessage()); } return objectItems; } }