List of usage examples for com.fasterxml.jackson.databind.node ArrayNode add
public ArrayNode add(JsonNode paramJsonNode)
From source file:org.apache.drill.optiq.DrillImplementor.java
public DrillImplementor() { final ObjectNode headNode = mapper.createObjectNode(); rootNode.put("head", headNode); headNode.put("type", "apache_drill_logical_plan"); headNode.put("version", "1"); final ObjectNode generatorNode = mapper.createObjectNode(); headNode.put("generator", generatorNode); generatorNode.put("type", "manual"); generatorNode.put("info", "na"); // TODO: populate sources based on the sources of scans that occur in // the query/*from w ww . j av a 2s .com*/ final ArrayNode sourcesNode = mapper.createArrayNode(); rootNode.put("storage", sourcesNode); // input file source { final ObjectNode sourceNode = mapper.createObjectNode(); sourceNode.put("name", "donuts-json"); sourceNode.put("type", "classpath"); sourcesNode.add(sourceNode); } { final ObjectNode sourceNode = mapper.createObjectNode(); sourceNode.put("name", "queue"); sourceNode.put("type", "queue"); sourcesNode.add(sourceNode); } final ArrayNode queryNode = mapper.createArrayNode(); rootNode.put("query", queryNode); final ObjectNode sequenceOpNode = mapper.createObjectNode(); queryNode.add(sequenceOpNode); sequenceOpNode.put("op", "sequence"); this.operatorsNode = mapper.createArrayNode(); sequenceOpNode.put("do", operatorsNode); }
From source file:com.vz.onosproject.zeromqprovider.AppWebResource.java
/** * Get all flows for all ZMQ devices//from w w w. jav a 2s .c o m * @return 200 OK */ @GET @Path("flows") @Produces(MediaType.APPLICATION_JSON) public Response getFlows() { ObjectNode root = mapper().createObjectNode(); ArrayNode flowsRootNode = root.putArray("Flows"); log.info("###### Getting All Flows"); List<String> devices = controller.getAvailableDevices(); if (devices == null) { flowsRootNode.add("No Flows"); } else { try { for (String d : devices) { DeviceId device = DeviceId.deviceId(d); ObjectNode devroot = mapper().createObjectNode(); ArrayNode devNode = devroot.putArray("Device Flows"); List<Blob> blobs = store.getBlobs(device); if (blobs.isEmpty()) { devNode.add("No Flows"); } else { for (Blob b : blobs) { devNode.add(new String(b.getBlob())); } } devroot.put("Device ID", device.toString()); flowsRootNode.add(devroot); } return Response.ok(root).build(); } catch (Exception e) { e.printStackTrace(); } } return Response.noContent().build(); }
From source file:com.attribyte.essem.DefaultResponseGenerator.java
protected String parseGraphAggregation(JsonNode sourceParent, List<String> fields, RateUnit rateUnit, ObjectNode targetMeta, ArrayNode targetGraph) { Iterator<Map.Entry<String, JsonNode>> iter = sourceParent.fields(); Map.Entry<String, JsonNode> aggregation = null; while (iter.hasNext()) { aggregation = iter.next();//from www .j a va 2s. c o m if (aggregation.getValue().isObject()) { break; } else { aggregation = null; } } if (aggregation == null) { return "Aggregation is invalid"; } String bucketName = aggregation.getKey(); JsonNode obj = aggregation.getValue(); JsonNode bucketsObj = obj.get("buckets"); if (bucketsObj == null || !bucketsObj.isArray()) { return "Aggregation is invalid"; } if (keyComponents.contains(bucketName)) { for (final JsonNode bucketObj : bucketsObj) { if (!bucketObj.isObject()) { return "Aggregation is invalid"; } JsonNode keyNode = bucketObj.get(KEY_NODE_KEY); if (keyNode == null) { return "Aggregation is invalid"; } targetMeta.put(translateBucketName(bucketName), keyNode.asText()); String error = parseGraphAggregation(bucketObj, fields, rateUnit, targetMeta.deepCopy(), targetGraph); if (error != null) { return error; } } return null; } else { ObjectNode graphObj = targetGraph.addObject(); addAggregationMeta(graphObj, targetMeta); ArrayNode samplesArr = graphObj.putArray("samples"); for (final JsonNode bucketObj : bucketsObj) { if (!bucketObj.isObject()) { return "Aggregation is invalid"; } JsonNode keyNode = bucketObj.get(KEY_NODE_KEY); if (keyNode == null) { return "Aggregation is invalid"; } ArrayNode sampleArr = samplesArr.addArray(); sampleArr.add(keyNode.asLong()); JsonNode docCountNode = bucketObj.get(SAMPLES_KEY); long samples = docCountNode != null ? docCountNode.asLong() : 0L; sampleArr.add(samples); for (String field : fields) { JsonNode fieldObj = bucketObj.get(field); if (fieldObj != null) { JsonNode valueNode = fieldObj.get("value"); if (rateUnit == RAW_RATE_UNIT || valueNode == null || !rateFields.contains(field)) { if (valueNode != null) { sampleArr.add(valueNode); } else { sampleArr.add(0L); } } else { sampleArr.add(valueNode.doubleValue() * rateUnit.mult); } } else { sampleArr.add(0L); } } } return null; } }
From source file:com.github.fge.jsonschema.core.report.ProcessingMessage.java
/** * Add a key/value pair to this message, where the value is a collection of * items/*from w ww . j a va2 s. c o m*/ * * <p>This will put all values (again, using {@link #toString()} of the * collection into an array.</p> * * @param key the key * @param values the collection of values * @param <T> the element type of the collection * @return this */ public <T> ProcessingMessage put(final String key, final Iterable<T> values) { if (values == null) return putNull(key); final ArrayNode node = FACTORY.arrayNode(); for (final T value : values) node.add(value == null ? FACTORY.nullNode() : FACTORY.textNode(value.toString())); return put(key, node); }
From source file:com.redhat.lightblue.ResponseTest.java
@Test public void testToJson() { response.setStatus(OperationStatus.COMPLETE); response.setModifiedCount(Integer.MAX_VALUE); response.setMatchCount(Integer.MIN_VALUE); response.setTaskHandle("taskHandle"); response.setSessionInfo(null);/*ww w.j a v a2s . co m*/ response.setEntityData(JsonObject.getFactory().objectNode()); response.getDataErrors().addAll(getPopulatedDataErrors(3)); response.getErrors().addAll(getPopulatedErrors(3)); ObjectNode expectedNode = JsonObject.getFactory().objectNode(); expectedNode.put("status", OperationStatus.COMPLETE.name().toLowerCase()); expectedNode.put("modifiedCount", Integer.MAX_VALUE); expectedNode.put("matchCount", Integer.MIN_VALUE); expectedNode.put("taskHandle", "taskHandle"); expectedNode.set("session", JsonObject.getFactory().objectNode()); expectedNode.set("entityData", JsonObject.getFactory().objectNode()); ArrayNode arr = JsonObject.getFactory().arrayNode(); expectedNode.set("dataErrors", arr); for (DataError err : getPopulatedDataErrors(3)) { arr.add(err.toJson()); } ArrayNode arr2 = JsonObject.getFactory().arrayNode(); expectedNode.set("errors", arr2); for (Error err : getPopulatedErrors(3)) { arr2.add(err.toJson()); } assertFalse(response.toJson().equals(expectedNode)); }
From source file:net.sf.taverna.t2.activities.apiconsumer.servicedescriptions.ApiConsumerServiceDescription.java
@Override public Configuration getActivityConfiguration() { Configuration configuration = new Configuration(); configuration.setType(ACTIVITY_TYPE.resolve("#Config")); ObjectNode json = (ObjectNode) configuration.getJson(); json.put("apiConsumerName", apiConsumerName); json.put("apiConsumerDescription", apiConsumerDescription); json.put("description", description); json.put("className", className); json.put("methodName", methodName); ArrayNode parameterNamesArray = json.arrayNode(); for (String parameterName : parameterNames) { parameterNamesArray.add(parameterName); }/* ww w . j a v a 2 s .c om*/ json.put("parameterNames", parameterNamesArray); ArrayNode parameterTypesArray = json.arrayNode(); for (String parameterType : parameterTypes) { parameterTypesArray.add(parameterType); } json.put("parameterTypes", parameterTypesArray); ArrayNode parameterDimensionsArray = json.arrayNode(); for (int parameterDimension : parameterDimensions) { parameterDimensionsArray.add(parameterDimension); } json.put("parameterDimensions", parameterDimensionsArray); json.put("returnType", returnType); json.put("returnDimension", returnDimension); json.put("isMethodConstructor", isConstructor); json.put("isMethodStatic", isStatic); return configuration; }
From source file:org.onosproject.EvacuateCommand.java
/** * Produces a JSON array of flows grouped by the each device. * * @param devices collection of devices to group flow by * @param flows collection of flows per each device * @return JSON array// w ww. j av a2 s. c om */ private JsonNode json(Iterable<Device> devices, Map<Device, List<FlowEntry>> flows) { ObjectMapper mapper = new ObjectMapper(); ArrayNode result = mapper.createArrayNode(); for (Device device : devices) { result.add(json(mapper, device, flows.get(device))); } return result; }
From source file:com.vz.onosproject.zeromqprovider.AppWebResource.java
/** * Get hello world greeting./* w ww . j av a2 s . com*/ * * @return 200 OK */ @GET @Path("devices") public Response getAllDevices() { ObjectNode root = mapper().createObjectNode(); ArrayNode devNode = root.putArray("ZMQ Devices"); log.info("###### Getting all zmq devices known to this provider"); List<String> devices = controller.getAvailableDevices(); if (devices == null) { devNode.add("No devices"); } else { for (String d : devices) { devNode.add(d); } } return ok(root).build(); }
From source file:de.jlo.talendcomp.json.JsonComparator.java
/** * Collects the values for the both arrays have in common * @param array1/*from ww w. ja va2 s .c om*/ * @param array2 * @return an array which contains all values both arrays have in common */ public ArrayNode intersect(ArrayNode array1, ArrayNode array2) { ArrayNode result = objectMapper.createArrayNode(); for (int i1 = 0, n1 = array1.size(); i1 < n1; i1++) { JsonNode node1 = array1.get(i1); for (int i2 = 0, n2 = array2.size(); i2 < n2; i2++) { JsonNode node2 = array2.get(i2); if (node1.equals(node2)) { result.add(node2); } } } return result; }
From source file:com.github.fge.jsonschema.processors.validation.InstanceValidator.java
private ProcessingMessage validationLoopMessage(final FullData input) { final String errmsg = validationMessages.getMessage("err.common.validationLoop"); final ArrayNode node = JacksonUtils.nodeFactory().arrayNode(); for (final Equivalence.Wrapper<FullData> e : visited) //noinspection ConstantConditions node.add(toJson(e.get())); return input.newMessage().put("domain", "validation").setMessage(errmsg) .putArgument("alreadyVisited", toJson(input)) .putArgument("instancePointer", input.getInstance().getPointer().toString()) .put("validationPath", node); }