List of usage examples for com.fasterxml.jackson.databind JsonNode toString
public abstract String toString();
From source file:com.evrythng.java.wrapper.mapping.TaskNotificationWayDeserializer.java
@Override public Task.Notification.Way deserialize(final JsonParser jp, final DeserializationContext ctx) throws IOException { ObjectMapper mapper = JSONUtils.OBJECT_MAPPER; JsonNode node = mapper.readTree(jp); JsonNode typeNode = node.get(TaskOnBatch.FIELD_TYPE); if (typeNode == null) { throw new JsonMappingException("Cannot deserialize task notification way without type field"); }// w ww . j a v a 2s. co m String typeRaw = getFieldValue(typeNode); Class<? extends Task.Notification.Way> subtypeClass = classForType( Task.Notification.Way.Type.valueOf(typeRaw.toUpperCase())); return mapper.readValue(node.toString(), subtypeClass); }
From source file:com.evrythng.java.wrapper.mapping.TaskResultDeserializer.java
@Override public TaskOnBatch.BaseTaskResult deserialize(final JsonParser jp, final DeserializationContext ctx) throws IOException { ObjectMapper mapper = JSONUtils.OBJECT_MAPPER; JsonNode node = mapper.readTree(jp); JsonNode typeNode = node.get(TaskOnBatch.FIELD_TYPE); if (typeNode == null) { throw new JsonMappingException("Cannot deserialize task result without type field"); }// w ww. ja va 2 s . c o m String typeRaw = getFieldValue(typeNode); Class<? extends TaskOnBatch.BaseTaskResult> subtypeClass = classForType( TaskOnBatch.BaseTaskResult.Type.valueOf(typeRaw.toUpperCase())); return mapper.readValue(node.toString(), subtypeClass); }
From source file:com.dnanexus.DXHTTPRequest.java
/** * Issues a request against the specified resource and returns the result as a JSON object. * * @param resource Name of resource, e.g. "/file-XXXX/describe" * @param data Request payload (to be converted to JSON) * @param retryStrategy Indicates whether the request is idempotent and can be retried * * @throws DXAPIException If the server returns a complete response with an HTTP status code * other than 200 (OK)./*w w w . ja v a2s .c o m*/ * @throws DXHTTPException If an error occurs while making the HTTP request or obtaining the * response (includes HTTP protocol errors). */ public JsonNode request(String resource, JsonNode data, RetryStrategy retryStrategy) { String dataAsString = data.toString(); return requestImpl(resource, dataAsString, true, retryStrategy).responseJson; }
From source file:portal.api.osm.client.OSMClient.java
public List<Nsd> getNSDs() { String response = getOSMResponse(BASE_SERVICE_URL + "/nsd-catalog/nsd"); ObjectMapper mapper = new ObjectMapper(new JsonFactory()); try {/* www . j av a 2s . com*/ JsonNode tr = mapper.readTree(response).findValue("nsd:nsd"); if (tr == null) { tr = mapper.readTree(response).findValue("nsd"); } ArrayList<Nsd> nsds = new ArrayList<>(); for (JsonNode jsonNode : tr) { Nsd nsd = mapper.readValue(jsonNode.toString(), Nsd.class); nsds.add(nsd); } return nsds; } catch (IllegalStateException | IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
From source file:portal.api.osm.client.OSMClient.java
public List<Vnfd> getVNFDs() { String response = getOSMResponse(BASE_SERVICE_URL + "/vnfd-catalog/vnfd"); ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); try {/*w ww. ja va 2 s.c o m*/ JsonNode tr = mapper.readTree(response).findValue("vnfd:vnfd"); if (tr == null) { tr = mapper.readTree(response).findValue("vnfd"); } ArrayList<Vnfd> vnfds = new ArrayList<>(); for (JsonNode jsonNode : tr) { Vnfd vnfd = mapper.readValue(jsonNode.toString(), Vnfd.class); vnfds.add(vnfd); } return vnfds; } catch (IllegalStateException | IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
From source file:com.attribyte.essem.DefaultResponseGenerator.java
private void generateGraph(JsonNode responseObject, HttpServletResponse response) throws IOException { response.setContentType(JSON_CONTENT_TYPE_HEADER); response.setStatus(HttpServletResponse.SC_OK); response.getOutputStream().write(responseObject.toString().getBytes("UTF-8")); response.getOutputStream().flush();//from w w w . j a va 2s.co m }
From source file:com.evrythng.java.wrapper.mapping.PropertyDeserializer.java
@Override public Property<?> deserialize(final JsonParser jp, final DeserializationContext ctx) throws IOException { ObjectMapper mapper = JSONUtils.OBJECT_MAPPER; JsonNode node = mapper.readTree(jp); JsonNode valueNode = node.get(Property.FIELD_VALUE); if (valueNode == null) { throw new JsonMappingException("Cannot deserialize property without value field"); }/*from w w w . jav a 2 s. c o m*/ Object value = getFieldValue(valueNode); Property.Type type = Property.Type.forPropertyValue(value); Class<? extends Property<?>> propertyClass = propertyClassForType(type); return mapper.readValue(node.toString(), propertyClass); }
From source file:com.epam.dlab.backendapi.core.commands.CommandExecutorMockAsync.java
/** * Return the section of resource statuses for docker action status. *///from w ww.j a v a2 s . c om private String getResponseStatus(boolean noUpdate) { if (noUpdate) { return "{}"; } EnvResourceList resourceList; try { JsonNode json = MAPPER.readTree(parser.getJson()); json = json.get("edge_list_resources"); resourceList = MAPPER.readValue(json.toString(), EnvResourceList.class); } catch (IOException e) { throw new DlabException("Can't parse json content: " + e.getLocalizedMessage(), e); } if (resourceList.getHostList() != null) { for (EnvResource host : resourceList.getHostList()) { host.setStatus(UserInstanceStatus.RUNNING.toString()); } } if (resourceList.getClusterList() != null) { for (EnvResource host : resourceList.getClusterList()) { host.setStatus(UserInstanceStatus.RUNNING.toString()); } } try { return MAPPER.writeValueAsString(resourceList); } catch (JsonProcessingException e) { throw new DlabException("Can't generate json content: " + e.getLocalizedMessage(), e); } }
From source file:com.okta.tools.awscli.java
private static String ProcessPolicyDocument(String policyDoc) { String strRoleToAssume = null; try {//from w w w. ja v a 2s . c o m String policyDocClean = URLDecoder.decode(policyDoc, "UTF-8"); logger.debug("Clean Policy Document: " + policyDocClean); ObjectMapper objectMapper = new ObjectMapper(); try { JsonNode rootNode = objectMapper.readTree(policyDocClean); JsonNode statement = rootNode.path("Statement"); logger.debug("Statement node: " + statement.toString()); JsonNode resource = null; if (statement.isArray()) { logger.debug("Statement is array"); for (int i = 0; i < statement.size(); i++) { String action = statement.get(i).path("Action").textValue(); if (action != null && action.equals("sts:AssumeRole")) { resource = statement.get(i).path("Resource"); logger.debug("Resource node: " + resource.toString()); break; } } } else { logger.debug("Statement is NOT array"); if (statement.get("Action").textValue().equals("sts:AssumeRole")) { resource = statement.path("Resource"); logger.debug("Resource node: " + resource.toString()); } } if (resource != null) { if (resource.isArray()) { //if we're handling a policy with an array of AssumeRole attributes ArrayList<String> lstRoles = new ArrayList<String>(); for (final JsonNode node : resource) { lstRoles.add(node.asText()); } strRoleToAssume = SelectRole(lstRoles); } else { strRoleToAssume = resource.textValue(); logger.debug("Role to assume: " + roleToAssume); } } } catch (IOException ioe) { } } catch (UnsupportedEncodingException uee) { } return strRoleToAssume; }
From source file:com.auditbucket.test.functional.TestWebServiceIntegration.java
public void jsonReadFiles() throws Exception { SecurityContextHolder.getContext().setAuthentication(authA); ObjectMapper mapper = new ObjectMapper(); String filename = "//tmp/new-trainprofiles.json"; InputStream is = new FileInputStream(filename); JsonNode node = mapper.readTree(is); System.out.println("node Count = " + node.size()); HttpClient httpclient = new DefaultHttpClient(); String url = "http://localhost:8080/ab-engine/track/header/new"; for (JsonNode profile : node.elements().next()) { HttpPost auditPost = new HttpPost(url); auditPost.addHeader("content-type", "application/json"); auditPost.addHeader("Authorization", "Basic bWlrZToxMjM="); MetaInputBean inputBean = new MetaInputBean("capacity", "system", "TrainProfile", DateTime.now(), profile.get("profileID").asText()); LogInputBean log = new LogInputBean("moira", null, profile.toString()); inputBean.setLog(log);/* w w w.ja v a 2s .c o m*/ log.setForceReindex(true); StringEntity json = new StringEntity(mapper.writeValueAsString(inputBean)); auditPost.setEntity(json); HttpResponse response = httpclient.execute(auditPost); BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent()))); String output; System.out.println("Output from Server .... \n"); while ((output = br.readLine()) != null) { System.out.println(output); } } }