List of usage examples for com.fasterxml.jackson.core JsonProcessingException printStackTrace
public void printStackTrace()
From source file:org.venice.piazza.servicecontroller.messaging.handlers.DescribeServiceHandlerTest.java
/** * Test that the service metadata can be retrieved. */// w w w . ja v a 2s. com @Test public void testSuccessDescribe() { DescribeServiceMetadataJob job = new DescribeServiceMetadataJob(); String testServiceId = "a842aae2-bd74-4c4b-9a65-c45e8cd9060"; job.serviceID = testServiceId; try { ObjectMapper mapper = new ObjectMapper(); String responseServiceString = mapper.writeValueAsString(service); ResponseEntity<String> responseEntity = new ResponseEntity<String>(responseServiceString, HttpStatus.OK); final DescribeServiceHandler dsMock = Mockito.spy(dsHandler); Mockito.doReturn(responseEntity).when(dsMock).handle(job); ResponseEntity<String> result = dsMock.handle(job); assertEquals("The response entity was correct for this describe request", responseEntity, result); assertEquals("The response code is 200", responseEntity.getStatusCode(), HttpStatus.OK); assertEquals("The body of the response is correct", responseEntity.getBody(), responseServiceString); } catch (JsonProcessingException jpe) { jpe.printStackTrace(); } }
From source file:edu.upenn.mkse212.pennbook.server.FeedServiceImpl.java
@Override public String addComment(String postId, String posterId, String posterName, String message) { HashMap<String, Object> commentMap = new HashMap<String, Object>(); commentMap.put(TIMESTAMP_ATTR, System.currentTimeMillis()); commentMap.put(POSTER_ID_ATTR, posterId); commentMap.put(POSTER_NAME_ATTR, posterName); commentMap.put(MESSAGE_ATTR, message); String commentAsJson = ""; try {/* ww w. j a v a2 s . co m*/ //comments will be stored as JSON commentAsJson = mapper.writeValueAsString(commentMap); } catch (JsonProcessingException e) { System.exit(1); e.printStackTrace(); } HashMap<String, String> map = new HashMap<String, String>(); map.put(COMMENT_ATTR, commentAsJson); List<String> feedItemIds = feedItemIdsByPostId(postId); for (String feedItemId : feedItemIds) //add comment to each copy of the post { store.put(feedItemId, map); } return commentAsJson; }
From source file:org.apache.streams.twitter.processor.TwitterEventProcessor.java
@Override public List<StreamsDatum> process(StreamsDatum entry) { // first check for valid json ObjectNode node = (ObjectNode) entry.getDocument(); LOGGER.debug("{} processing {}", STREAMS_ID, node.getClass()); String json = null;/*w w w . j av a 2 s . c o m*/ try { json = mapper.writeValueAsString(node); } catch (JsonProcessingException e) { e.printStackTrace(); } if (StringUtils.isNotEmpty(json)) { // since data is coming from outside provider, we don't know what type the events are Class inClass = TwitterEventClassifier.detectClass(json); // if the target is string, just pass-through if (java.lang.String.class.equals(outClass)) return Lists.newArrayList(new StreamsDatum(json)); else { // convert to desired format Object out = null; try { out = convert(node, inClass, outClass); } catch (ActivitySerializerException e) { LOGGER.warn("Failed deserializing", e); return Lists.newArrayList(); } catch (JsonProcessingException e) { LOGGER.warn("Failed parsing JSON", e); return Lists.newArrayList(); } if (out != null && validate(out, outClass)) return Lists.newArrayList(new StreamsDatum(out)); } } return Lists.newArrayList(); }
From source file:com.sm.store.TestRemoteCall.java
public void testJson() { ObjectMapper mapper = new ObjectMapper(); int i = 1;/*from www. ja va 2 s.co m*/ Person.Address address = new Person.Address(new Person.Street(i, "test-1" + i), (90300 + i), "cypress"); Person person = new Person("mickey", i, 4000.00, true, address); try { System.out.println(mapper.writeValueAsString(person)); System.out.println(mapper.writeValueAsString(address)); } catch (JsonProcessingException e) { e.printStackTrace(); } }
From source file:de.minestar.minestarlibrary.chat.ChatMessage.java
public String toJSONString() { try {/*from www . j a v a2s.c o m*/ return JSON_MAPPER.writeValueAsString(this); } catch (JsonProcessingException e) { e.printStackTrace(); return null; } }
From source file:org.apache.streams.json.JsonPathFilter.java
@Override public List<StreamsDatum> process(StreamsDatum entry) { List<StreamsDatum> result = Lists.newArrayList(); String json = null;/*from www .j a va 2s .com*/ ObjectNode document = null; LOGGER.debug("{} processing {}", STREAMS_ID); if (entry.getDocument() instanceof ObjectNode) { document = (ObjectNode) entry.getDocument(); try { json = mapper.writeValueAsString(document); } catch (JsonProcessingException e) { e.printStackTrace(); } } else if (entry.getDocument() instanceof String) { json = (String) entry.getDocument(); try { document = mapper.readValue(json, ObjectNode.class); } catch (IOException e) { e.printStackTrace(); return null; } } Preconditions.checkNotNull(document); if (StringUtils.isNotEmpty(json)) { Object srcResult = null; try { srcResult = jsonPath.read(json); } catch (Exception e) { e.printStackTrace(); LOGGER.warn(e.getMessage()); } Preconditions.checkNotNull(srcResult); String[] path = StringUtils.split(pathExpression, '.'); ObjectNode node = document; for (int i = 1; i < path.length - 1; i++) { node = (ObjectNode) document.get(path[i]); } Preconditions.checkNotNull(node); if (srcResult instanceof JSONArray) { try { ArrayNode jsonNode = mapper.convertValue(srcResult, ArrayNode.class); if (jsonNode.size() == 1) { JsonNode item = jsonNode.get(0); node.set(destNodeName, item); } else { node.set(destNodeName, jsonNode); } } catch (Exception e) { LOGGER.warn(e.getMessage()); } } else if (srcResult instanceof JSONObject) { try { ObjectNode jsonNode = mapper.convertValue(srcResult, ObjectNode.class); node.set(destNodeName, jsonNode); } catch (Exception e) { LOGGER.warn(e.getMessage()); } } else if (srcResult instanceof String) { try { node.put(destNodeName, (String) srcResult); } catch (Exception e) { LOGGER.warn(e.getMessage()); } } } result.add(new StreamsDatum(document)); return result; }
From source file:ac.ucy.cs.spdx.service.Compatibility.java
@POST @Path("/edge/") @Consumes(MediaType.TEXT_PLAIN)/*from ww w . j av a2s . c o m*/ @Produces(MediaType.APPLICATION_JSON) public String addEdge(String jsonString) { ObjectMapper mapper = new ObjectMapper(); JsonNode licenseEdge = null; try { licenseEdge = mapper.readTree(jsonString); } catch (JsonProcessingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } ArrayList<String> licenseNodes = new ArrayList<String>(); String nodeIdentifier = licenseEdge.get("nodeIdentifier").toString(); nodeIdentifier = nodeIdentifier.substring(1, nodeIdentifier.length() - 1); String transitivity = licenseEdge.get("transitivity").toString(); transitivity = transitivity.substring(1, transitivity.length() - 1); Boolean isTransitive = Boolean.parseBoolean(transitivity); JsonNode nodesJSON = licenseEdge.get("nodeIdentifiers"); for (int i = 0; i < nodesJSON.size(); i++) { String node = nodesJSON.get(i).get("identifier").toString(); node = node.substring(1, node.length() - 1); licenseNodes.add(node); } try { LicenseGraph.connectNode(isTransitive, nodeIdentifier, licenseNodes.toArray(new String[licenseNodes.size()])); } catch (LicenseEdgeAlreadyExistsException e) { e.printStackTrace(); return "{\"status\":\"failure\",\"message\":\"" + e.getMessage() + "\"}"; } LicenseGraph.exportGraph(); return "{\"status\":\"success\",\"message\":\"" + nodeIdentifier + " -> " + licenseNodes.toString() + " added in the system.\"}";// {"nodeIdentifier":"Caldera","transitivity":"true","nodeIdentifiers":[{"identifier":"Apache-2.0"}]} }
From source file:ac.ucy.cs.spdx.service.Compatibility.java
@POST @Path("/compatible/") @Consumes(MediaType.TEXT_PLAIN)//w w w .ja v a 2s. c om @Produces(MediaType.APPLICATION_JSON) public String areCompatible(String jsonString) { ObjectMapper mapper = new ObjectMapper(); JsonNode fileNode = null; try { fileNode = mapper.readTree(jsonString); } catch (JsonProcessingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } ArrayList<String> licenses = new ArrayList<String>(); JsonNode licensesJSON = fileNode.get("licenses"); StringBuilder compatibleJSON = new StringBuilder(); for (int i = 0; i < licensesJSON.size(); i++) { String licenseId = licensesJSON.get(i).get("identifier").toString(); licenseId = licenseId.substring(1, licenseId.length() - 1); licenses.add(licenseId); } boolean compatible = LicenseCompatibility.areCompatible(licenses.toArray(new String[licenses.size()])); boolean adjustable = true; ArrayList<License> proposed = new ArrayList<License>(); if (!compatible) { LicenseCompatibility.proposeLicense(licenses.toArray(new String[licenses.size()])); } if (proposed.isEmpty()) { adjustable = false; } compatibleJSON.append( "{\"compatible\":\"" + compatible + "\",\"adjustable\":\"" + adjustable + "\",\"proposals\":["); for (License proposal : proposed) { compatibleJSON.append("{\"identifier\":\"" + proposal.getIdentifier() + "\"},"); } if (adjustable) { compatibleJSON.deleteCharAt(compatibleJSON.length() - 1); } compatibleJSON.append("]}"); return compatibleJSON.toString();// {"licenses":[{"identifier":"Apache-2.0"},{"identifier":"MPL-2.0"}]} }
From source file:ac.ucy.cs.spdx.service.SpdxViolationAnalysis.java
@POST @Path("/validate/") @Consumes(MediaType.TEXT_PLAIN)//w w w .j a va 2s. c o m @Produces(MediaType.APPLICATION_JSON) public String validateSpdx(String jsonString) throws InvalidSPDXAnalysisException { ObjectMapper mapper = new ObjectMapper(); JsonNode fileNode = null; try { fileNode = mapper.readTree(jsonString); } catch (JsonProcessingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } String fileName = fileNode.get("filename").toString(); fileName = fileName.substring(1, fileName.length() - 1); String content = fileNode.get("content").toString(); content = StringEscapeUtils.unescapeXml(content); content = content.substring(1, content.length() - 1); SpdxLicensePairConflictError analysis = null; CaptureLicense captured = null; try { captured = new CaptureLicense(ParseRdf.parseToRdf(fileName, content)); } catch (InvalidLicenseStringException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } try { analysis = new SpdxLicensePairConflictError(captured); } catch (UnsupportedSpdxVersionException e) { e.printStackTrace(); } return analysis.toJson();// {"filename":"","content":""} }
From source file:ac.ucy.cs.spdx.service.Compatibility.java
@POST @Path("/node/") @Consumes(MediaType.TEXT_PLAIN)/*from w w w . j a va2s . c o m*/ @Produces(MediaType.APPLICATION_JSON) public String addNode(String jsonString) { ObjectMapper mapper = new ObjectMapper(); JsonNode licenseNode = null; try { licenseNode = mapper.readTree(jsonString); } catch (JsonProcessingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } ArrayList<String> licenses = new ArrayList<String>(); String nodeIdentifier = licenseNode.get("nodeIdentifier").toString(); nodeIdentifier = nodeIdentifier.substring(1, nodeIdentifier.length() - 1); String nodeCategory = licenseNode.get("nodeCategory").toString(); nodeCategory = nodeCategory.substring(1, nodeCategory.length() - 1); Category category = Category.UNCATEGORIZED; if (nodeCategory == "PERMISSIVE") { category = Category.PERMISSIVE; } else if (nodeCategory == "WEAK_COPYLEFT") { category = Category.WEAK_COPYLEFT; } else if (nodeCategory == "STRONG_COPYLEFT") { category = Category.STRONG_COPYLEFT; } else { category = Category.UNCATEGORIZED; } JsonNode licensesJSON = licenseNode.get("nodelicenses"); for (int i = 0; i < licensesJSON.size(); i++) { String licenseId = licensesJSON.get(i).get("identifier").toString(); licenseId = licenseId.substring(1, licenseId.length() - 1); licenses.add(licenseId); } try { LicenseGraph.addLicenseNode(nodeIdentifier, category, licenses.toArray(new String[licenses.size()])); } catch (LicenseNodeAlreadyExistsException e) { e.printStackTrace(); return "{\"status\":\"failure\",\"message\":\"" + e.getMessage() + "\"}"; } LicenseGraph.exportGraph(); return "{\"status\":\"success\",\"message\":\"" + nodeIdentifier + " added in the system.\"}";// {"nodeIdentifier":"Caldera","nodeCategory":"PERMISSIVE","nodelicenses":[{"identifier":"Caldera"}]} }