List of usage examples for com.fasterxml.jackson.databind.node ObjectNode putPOJO
public ObjectNode putPOJO(String paramString, Object paramObject)
From source file:org.apache.taverna.examples.JsonExport.java
protected JsonNode toJson(Processor proc) { ObjectNode p = mapper.createObjectNode(); p.putPOJO("id", uriTools.relativeUriForBean(proc, proc.getParent().getParent())); p.put("name", proc.getName()); addPorts(proc, p);/*from ww w . j a v a 2 s . c o m*/ p.putAll(annotations(proc)); List<Workflow> nested = scufl2Tools.nestedWorkflowsForProcessor(proc, proc.getParent().getParent().getMainProfile()); if (!nested.isEmpty()) { if (nested.size() == 1) { p.put("nestedWorkflow", toJson(nested.iterator().next())); } else { ArrayNode list = mapper.createArrayNode(); for (Workflow w : nested) { list.add(toJson(w)); } p.put("nestedWorkflow", list); } } return p; }
From source file:org.apache.taverna.examples.JsonExport.java
protected JsonNode toJson(Revision currentRevision) { ArrayNode revisions = mapper.createArrayNode(); while (currentRevision != null) { ObjectNode rev = mapper.createObjectNode(); rev.putPOJO("id", currentRevision.getIdentifier()); if (currentRevision.getGeneratedAtTime() != null) { rev.putPOJO("generatedAtTime", currentRevision.getGeneratedAtTime()); }//w w w . j a va 2 s. co m currentRevision = currentRevision.getPreviousRevision(); if (currentRevision != null) { rev.putPOJO("wasRevisionOf", currentRevision.getIdentifier()); } revisions.add(rev); } return revisions; }
From source file:org.apache.taverna.examples.JsonExport.java
protected ObjectNode toJson(Workflow workflow) { ObjectNode wf = mapper.createObjectNode(); wf.putPOJO("id", uriTools.relativeUriForBean(workflow, workflow.getParent())); wf.put("name", workflow.getName()); wf.put("revisions", toJson(workflow.getCurrentRevision())); ArrayNode processors = mapper.createArrayNode(); for (Processor p : workflow.getProcessors()) { processors.add(toJson(p));//w w w . j a v a2 s . c om } addPorts(workflow, wf); wf.put("processors", processors); ArrayNode datalinks = mapper.createArrayNode(); for (DataLink link : workflow.getDataLinks()) { datalinks.add(toJson(link)); } wf.put("datalinks", datalinks); ArrayNode controlLinks = mapper.createArrayNode(); for (ControlLink link : workflow.getControlLinks()) { controlLinks.add(toJson(link)); } wf.put("controllinks", controlLinks); wf.putAll(annotations(workflow)); return wf; }
From source file:org.apache.taverna.examples.JsonExport.java
protected ObjectNode toJson(Port port) { ObjectNode p = mapper.createObjectNode(); p.put("name", port.getName()); p.putPOJO("id", uriTools.relativeUriForBean(port, scufl2Tools.findParent(WorkflowBundle.class, ((Child<?>) port)))); if (port instanceof DepthPort) { DepthPort depthPort = (DepthPort) port; if (depthPort.getDepth() != null) { p.put("depth", depthPort.getDepth()); }// w ww . j a v a2s .c o m } if (port instanceof GranularDepthPort) { GranularDepthPort granularDepthPort = (GranularDepthPort) port; if (granularDepthPort.getGranularDepth() != null && !granularDepthPort.getGranularDepth().equals(granularDepthPort.getDepth())) { p.put("granularDepth", granularDepthPort.getGranularDepth()); } } p.putAll(annotations((Child<?>) port)); return p; }
From source file:org.springframework.tuple.TupleToJsonStringConverter.java
private ObjectNode toObjectNode(Tuple source) { ObjectNode root = mapper.createObjectNode(); for (int i = 0; i < source.size(); i++) { Object value = source.getValues().get(i); String name = source.getFieldNames().get(i); if (value == null) { root.putNull(name);//from w w w.j a v a2s . c o m } else { root.putPOJO(name, toNode(value)); } } return root; }
From source file:com.aerofs.baseline.metrics.MetricsCommand.java
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override// w w w .ja v a 2s .c o m public void execute(MultivaluedMap<String, String> queryParameters, PrintWriter entityWriter) throws Exception { MetricRegistry registry = MetricRegistries.getRegistry(); ObjectNode root = mapper.createObjectNode(); for (Map.Entry<String, Counter> entry : registry.getCounters().entrySet()) { ObjectNode node = getParent(root, entry.getKey()); node.put("count", entry.getValue().getCount()); } for (Map.Entry<String, Gauge> entry : registry.getGauges().entrySet()) { ObjectNode node = getParent(root, entry.getKey()); node.putPOJO("value", entry.getValue().getValue()); } for (Map.Entry<String, Histogram> entry : registry.getHistograms().entrySet()) { ObjectNode node = getParent(root, entry.getKey()); dumpSnapshot(entry.getValue().getSnapshot(), node); } for (Map.Entry<String, Meter> entry : registry.getMeters().entrySet()) { ObjectNode node = getParent(root, entry.getKey()); dumpMetered(node, entry.getValue()); } for (Map.Entry<String, Timer> entry : registry.getTimers().entrySet()) { ObjectNode node = getParent(root, entry.getKey()); dumpMetered(node, entry.getValue()); dumpSnapshot(entry.getValue().getSnapshot(), node); } Object serialized = mapper.treeToValue(root, Object.class); Commands.outputFormattedJson(mapper, entityWriter, queryParameters, serialized); }
From source file:org.apache.taverna.examples.JsonExport.java
protected JsonNode toJson(ControlLink link) { ObjectNode l = mapper.createObjectNode(); if (link instanceof BlockingControlLink) { BlockingControlLink controlLink = (BlockingControlLink) link; l.putPOJO("block", uriTools.relativeUriForBean(controlLink.getBlock(), link.getParent().getParent())); l.putPOJO("untilFinished", uriTools.relativeUriForBean(controlLink.getUntilFinished(), link.getParent().getParent())); }//from w ww. ja v a 2 s . c o m return l; }
From source file:org.forgerock.openicf.connectors.elastic.ElasticConnector.java
private byte[] attributesToBytes(Set<Attribute> attributes) { try {/*from w w w . j ava 2 s .c o m*/ final ObjectMapper mapper = new ObjectMapper(); final ObjectNode objectNode = mapper.createObjectNode(); for (Attribute attr : attributes) { final List<Object> value = attr.getValue(); objectNode.putPOJO(attr.getName(), value != null && value.size() > 1 ? value : AttributeUtil.getSingleValue(attr)); } return mapper.writeValueAsBytes(objectNode); } catch (JsonProcessingException e) { logger.error(e, null); return new byte[0]; } }
From source file:controllers.user.CommentApp.java
/** * ?// w ww . j a v a2s . c o m * * @return */ @Transactional public static Result list() { JsonNode json = getJson(); int pageIndex = json.findPath("pageIndex").asInt(1); int pageSize = json.findPath("pageSize").asInt(10); Long userId = json.findPath("userId").asLong(0); Long serviceId = json.findPath("serviceId").asLong(0); int level = json.findPath("level").asInt(0); String type = json.findPath("type").asText(); ObjectNode result = Json.newObject(); List<ObjectNode> nodes = new ArrayList<ObjectNode>(); List<Integer> levelList = new ArrayList<Integer>(); if (level != 0) levelList.add(level); Page<Comment> page = null; if (type.equals("expert")) { ExpertComment comment = new ExpertComment(); page = comment.getExpertParentComments(pageIndex, pageSize, userId, null, levelList); } else if (type.equals("service")) { ServiceComment comment = new ServiceComment(); page = comment.getExpertParentComments(pageIndex, pageSize, null, serviceId, levelList); } result.put("totalRecords", page.getTotalRowCount()); if (CollectionUtils.isNotEmpty(page.getList())) { for (Comment c : page.getList()) { ObjectNode node = Json.newObject(); node.put("headUrl", c.commentUser.getAvatar(70)); node.put("id", c.id); node.put("uid", c.commentUser.id); node.put("username", c.commentUser.getName()); node.put("level", c.level); node.put("commentTime", DateUtils.format(c.commentTime, DateUtils.FORAMT_DATE_TIME)); node.put("content", c.content); nodes.add(node); } } result.putPOJO("comments", nodes); return ok(result); }
From source file:org.envirocar.server.rest.encoding.json.SensorJSONEncoder.java
@Override public ObjectNode encodeJSON(Sensor t, AccessRights rights, MediaType mediaType) { ObjectNode sensor = getJsonFactory().objectNode(); if (t.hasType()) { sensor.put(JSONConstants.TYPE_KEY, t.getType()); }/*from ww w .j ava 2 s. c o m*/ Map<String, Object> properties = Maps.newHashMap(); if (t.hasProperties()) { properties.putAll(t.getProperties()); } properties.put(JSONConstants.IDENTIFIER_KEY, t.getIdentifier()); if (mediaType.equals(MediaTypes.SENSOR_TYPE)) { if (t.hasCreationTime()) { properties.put(JSONConstants.CREATED_KEY, getDateTimeFormat().print(t.getCreationTime())); } if (t.hasModificationTime()) { properties.put(JSONConstants.MODIFIED_KEY, getDateTimeFormat().print(t.getModificationTime())); } } sensor.putPOJO(JSONConstants.PROPERTIES_KEY, properties); return sensor; }