Example usage for com.fasterxml.jackson.databind.node ArrayNode add

List of usage examples for com.fasterxml.jackson.databind.node ArrayNode add

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind.node ArrayNode add.

Prototype

public ArrayNode add(JsonNode paramJsonNode) 

Source Link

Usage

From source file:fr.gouv.vitam.query.construct.action.Action.java

protected final void createActionVariables(final UPDATE action, final String... variableNames)
        throws InvalidCreateOperationException {
    final ArrayNode node = ((ObjectNode) currentObject).putArray(action.exactToken());
    for (final String var : variableNames) {
        if (var != null && !var.trim().isEmpty()) {
            node.add(var.trim());
        }//from  w w  w. j ava  2 s .  co m
    }
    currentObject = node;
}

From source file:org.apache.taverna.scufl2.translator.t2flow.defaultactivities.SpreadsheetActivityParser.java

private void makeRange(SpreadsheetRange range, ObjectNode rangeJson) {
    rangeJson.put("start", range.getStart().longValue());
    rangeJson.put("end", range.getEnd().longValue());

    ArrayNode excludes = rangeJson.arrayNode();
    for (SpreadsheetRange excludesRange : range.getExcludes().getExclude()) {
        ObjectNode exclude = rangeJson.objectNode();
        makeRange(excludesRange, exclude);
        excludes.add(exclude);
    }//  ww  w.ja v a2  s .c o  m
    if (excludes.size() > 0)
        rangeJson.put("excludes", excludes);
}

From source file:org.n52.io.geojson.GeoJSONEncoder.java

protected ArrayNode encodeCoordinate(Coordinate coordinate) {

    ArrayNode array = jsonFactory.arrayNode().add(coordinate.x).add(coordinate.y);

    if (!Double.isNaN(coordinate.z)) {
        array.add(coordinate.z);
    }/*from  w  w w.  j  ava  2s  .  co  m*/

    return array;
}

From source file:net.sf.taverna.t2.activities.beanshell.views.BeanshellConfigurationPanel.java

@Override
public void noteConfiguration() {
    setProperty("script", scriptConfigurationComponent.getScript());
    setProperty("classLoaderSharing", dependencyConfigurationPanel.getClassLoaderSharing());
    List<String> localDependencies = dependencyConfigurationPanel.getLocalDependencies();
    if (localDependencies == null || localDependencies.isEmpty()) {
        getJson().remove("localDependency");
    } else {/*from  w  ww.j a  va2  s. com*/
        ArrayNode localDependenciesArray = getJson().arrayNode();
        for (String localDependency : localDependencies) {
            localDependenciesArray.add(localDependency);
        }
        getJson().put("localDependency", localDependenciesArray);
    }
}

From source file:com.redhat.lightblue.Response.java

/**
 * Returns the entity data resulting from the call.
 *//* w  w w  .  jav  a  2  s .  c om*/
public void setEntityData(JsonNode node) {
    // if the node is not an array then wrap it in an array
    if (node != null && !node.isArray()) {
        ArrayNode arrayNode = new ArrayNode(jsonNodeFactory);
        arrayNode.add(node);
        entityData = arrayNode;
    } else {
        entityData = node;
    }
}

From source file:org.onosproject.tvue.TopologyResource.java

@javax.ws.rs.Path("/graph")
@GET//from   www.j  a v  a  2s  .  co  m
@Produces("application/json")
public Response graph() {
    ObjectMapper mapper = new ObjectMapper();

    // Fetch the services we'll be using.
    DeviceService deviceService = get(DeviceService.class);
    HostService hostService = get(HostService.class);
    TopologyService topologyService = get(TopologyService.class);

    // Fetch the current topology and its graph that we'll use to render.
    Topology topo = topologyService.currentTopology();
    TopologyGraph graph = topologyService.getGraph(topo);

    // Build all interior vertexes, i.e. no end-station hosts yet
    ArrayNode vertexesNode = mapper.createArrayNode();
    for (TopologyVertex vertex : graph.getVertexes()) {
        vertexesNode.add(json(mapper, vertex.deviceId(), 2, vertex.deviceId().uri().getSchemeSpecificPart(),
                deviceService.isAvailable(vertex.deviceId())));
    }

    // Now scan all links and count number of them between the same devices
    // using a normalized link key.
    Map<String, AggLink> linkRecords = aggregateLinks();

    // Now build all interior edges using the aggregated links.
    ArrayNode edgesNode = mapper.createArrayNode();
    for (AggLink lr : linkRecords.values()) {
        edgesNode.add(json(mapper, lr.links.size(), lr.link.src(), lr.link.dst()));
    }

    // Merge the exterior and interior vertexes and inject host links as
    // the exterior edges.
    for (Host host : hostService.getHosts()) {
        Set<IpAddress> ipAddresses = host.ipAddresses();
        IpAddress ipAddress = ipAddresses.isEmpty() ? null : ipAddresses.iterator().next();
        String label = ipAddress != null ? ipAddress.toString() : host.mac().toString();
        vertexesNode.add(json(mapper, host.id(), 3, label, true));
        edgesNode.add(json(mapper, 1, host.location(), new ConnectPoint(host.id(), portNumber(-1))));
    }

    // Now put the vertexes and edges into a root node and ship them off
    ObjectNode rootNode = mapper.createObjectNode();
    rootNode.set("vertexes", vertexesNode);
    rootNode.set("edges", edgesNode);
    return Response.ok(rootNode.toString()).build();
}

From source file:org.apache.taverna.examples.JsonExport.java

protected void addPorts(Ported ported, ObjectNode p) {
    ArrayNode inputs = mapper.createArrayNode();
    for (Port port : ported.getInputPorts()) {
        inputs.add(toJson(port));
    }//from www. jav a 2 s  .c o m
    p.put("inputs", inputs);

    ArrayNode outputs = mapper.createArrayNode();
    for (Port port : ported.getOutputPorts()) {
        outputs.add(toJson(port));
        // FIXME: Do we need the id for ports? Needed if we add datalinks
    }
    p.put("outputs", outputs);
}

From source file:scott.barleyrs.rest.QueryResultMessageBodyWriter.java

@Override
public void writeTo(QueryResult<?> result, Class<?> type, Type genericType, Annotation[] annotations,
        MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream)
        throws IOException, WebApplicationException {
    System.out.println("converting QueryResult to JSON");
    result.getEntityContext().setEntityContextState(EntityContextState.INTERNAL);
    try {/*from www. ja v a  2 s.  c om*/
        ObjectMapper mapper = new ObjectMapper();
        JsonGenerator gen = mapper.getFactory().createGenerator(entityStream);
        ArrayNode array = mapper.createArrayNode();
        for (Entity entity : result.getEntityList()) {
            Set<Entity> started = new HashSet<>();
            array.add(toJson(mapper, entity, started));

        }
        gen.writeTree(array);
    } finally {
        result.getEntityContext().setEntityContextState(EntityContextState.USER);
    }

}

From source file:com.google.api.server.spi.request.RestServletRequestParamReader.java

@Override
public Object[] read() throws ServiceException {
    // Assumes input stream to be encoded in UTF-8
    // TODO: Take charset from content-type as encoding
    try {/*from   w w w .  j  av a2 s . c  o  m*/
        EndpointMethod method = getMethod();
        if (method.getParameterClasses().length == 0) {
            return new Object[0];
        }
        String requestBody = IoUtil.readRequestBody(servletRequest);
        logger.log(Level.FINE, "requestBody=" + requestBody);
        // Unlike the Lily protocol, which essentially always requires a JSON body to exist (due to
        // path and query parameters being injected into the body), bodies are optional here, so we
        // create an empty body and inject named parameters to make deserialize work.
        JsonNode node = Strings.isEmptyOrWhitespace(requestBody) ? objectReader.createObjectNode()
                : objectReader.readTree(requestBody);
        if (!node.isObject()) {
            throw new BadRequestException("expected a JSON object body");
        }
        ObjectNode body = (ObjectNode) node;
        Map<String, Class<?>> parameterMap = getParameterMap(method);
        // First add query parameters, then add path parameters. If the parameters already exist in
        // the resource, then the they aren't added to the body object. For compatibility reasons,
        // the order of precedence is resource field > query parameter > path parameter.
        for (Enumeration<?> e = servletRequest.getParameterNames(); e.hasMoreElements();) {
            String parameterName = (String) e.nextElement();
            if (!body.has(parameterName)) {
                Class<?> parameterClass = parameterMap.get(parameterName);
                ApiParameterConfig parameterConfig = parameterConfigMap.get(parameterName);
                if (parameterClass != null && parameterConfig.isRepeated()) {
                    ArrayNode values = (ArrayNode) objectReader.createArrayNode();
                    for (String value : servletRequest.getParameterValues(parameterName)) {
                        values.add(value);
                    }
                    body.set(parameterName, values);
                } else {
                    body.put(parameterName, servletRequest.getParameterValues(parameterName)[0]);
                }
            }
        }
        for (Entry<String, String> entry : rawPathParameters.entrySet()) {
            String parameterName = entry.getKey();
            Class<?> parameterClass = parameterMap.get(parameterName);
            if (parameterClass != null && !body.has(parameterName)) {
                body.put(parameterName, entry.getValue());
            }
        }
        for (Entry<String, ApiParameterConfig> entry : parameterConfigMap.entrySet()) {
            if (!body.has(entry.getKey()) && entry.getValue().getDefaultValue() != null) {
                body.put(entry.getKey(), entry.getValue().getDefaultValue());
            }
        }
        return deserializeParams(body);
    } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | IOException e) {
        e.printStackTrace();
        throw new BadRequestException(e);
    }
}

From source file:org.n52.io.geojson.GeoJSONEncoder.java

protected ObjectNode encode(MultiPoint geometry, int parentSrid) {
    checkNotNull(geometry);//from   w ww  . j a va2s  . c om
    ObjectNode json = jsonFactory.objectNode();
    ArrayNode list = json.put(TYPE, MULTI_POINT).putArray(COORDINATES);
    for (int i = 0; i < geometry.getNumGeometries(); ++i) {
        list.add(encodeCoordinates((Point) geometry.getGeometryN(i)));
    }
    encodeCRS(json, geometry, parentSrid);
    return json;
}