Search in sources :

Example 96 with ArrayNode

use of com.fasterxml.jackson.databind.node.ArrayNode in project asterixdb by apache.

the class NodesAPIIntegrationTest method getNodeIds.

private List<String> getNodeIds() throws IOException, URISyntaxException {
    ArrayNode nodes = getNodeSummaries();
    final int size = nodes.size();
    List<String> nodeIds = new ArrayList<>();
    for (int i = 0; i < size; ++i) {
        nodeIds.add(nodes.get(i).get("node-id").asText());
    }
    return nodeIds;
}
Also used : ArrayList(java.util.ArrayList) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 97 with ArrayNode

use of com.fasterxml.jackson.databind.node.ArrayNode in project asterixdb by apache.

the class ABinary method toJSON.

@Override
public ObjectNode toJSON() {
    ObjectMapper om = new ObjectMapper();
    ObjectNode json = om.createObjectNode();
    int start = getStart();
    ArrayNode byteArray = om.createArrayNode();
    for (int i = 0; i < getLength(); i++) {
        byteArray.add(bytes[start + i]);
    }
    json.set("ABinary", byteArray);
    return json;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 98 with ArrayNode

use of com.fasterxml.jackson.databind.node.ArrayNode in project JMRI by JMRI.

the class JsonNamedBeanHttpService method getNamedBean.

/**
     * Create the JsonNode for a {@link jmri.NamedBean} object.
     *
     * @param bean   the bean to create the node for
     * @param name   the name of the bean; used only if the bean is null
     * @param type   the JSON type of the bean
     * @param locale the locale used for any error messages
     * @return a JSON node
     * @throws JsonException if the bean is null
     */
@Nonnull
protected ObjectNode getNamedBean(NamedBean bean, @Nonnull String name, @Nonnull String type, @Nonnull Locale locale) throws JsonException {
    if (bean == null) {
        throw new JsonException(404, Bundle.getMessage(locale, "ErrorObject", type, name));
    }
    ObjectNode root = mapper.createObjectNode();
    root.put(JSON.TYPE, type);
    ObjectNode data = root.putObject(JSON.DATA);
    data.put(JSON.NAME, bean.getSystemName());
    data.put(JSON.USERNAME, bean.getUserName());
    data.put(JSON.COMMENT, bean.getComment());
    ArrayNode properties = root.putArray(JSON.PROPERTIES);
    bean.getPropertyKeys().stream().forEach((key) -> {
        Object value = bean.getProperty(key);
        if (value != null) {
            properties.add(mapper.createObjectNode().put(key, value.toString()));
        } else {
            properties.add(mapper.createObjectNode().putNull(key));
        }
    });
    return data;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Nonnull(javax.annotation.Nonnull)

Example 99 with ArrayNode

use of com.fasterxml.jackson.databind.node.ArrayNode in project JMRI by JMRI.

the class JsonConsistHttpService method getConsist.

/**
     * Get the JSON representation of a consist.
     *
     * The JSON representation is an object with the following data attributes:
     * <ul>
     * <li>address - integer address</li>
     * <li>isLongAddress - boolean true if address is long, false if short</li>
     * <li>type - integer, see {@link jmri.Consist#getConsistType() }</li>
     * <li>id - string with consist Id</li>
     * <li>sizeLimit - the maximum number of locomotives the consist can
     * contain</li>
     * <li>engines - array listing every locomotive in the consist. Each entry
     * in the array contains the following attributes:
     * <ul>
     * <li>address - integer address</li>
     * <li>isLongAddress - boolean true if address is long, false if short</li>
     * <li>forward - boolean true if the locomotive running is forward in the
     * consists</li>
     * <li>position - integer locomotive's position in the consist</li>
     * </ul>
     * </ul>
     *
     * @param locale  The locale to throw exceptions in.
     * @param address The address of the consist to get.
     * @return The JSON representation of the consist.
     * @throws JsonException This exception has code 404 if the consist does not
     *                       exist.
     */
public JsonNode getConsist(Locale locale, DccLocoAddress address) throws JsonException {
    if (this.manager.getConsistList().contains(address)) {
        ObjectNode root = mapper.createObjectNode();
        root.put(TYPE, CONSIST);
        ObjectNode data = root.putObject(DATA);
        Consist consist = this.manager.getConsist(address);
        data.put(ADDRESS, consist.getConsistAddress().getNumber());
        data.put(IS_LONG_ADDRESS, consist.getConsistAddress().isLongAddress());
        data.put(TYPE, consist.getConsistType());
        ArrayNode engines = data.putArray(ENGINES);
        consist.getConsistList().stream().forEach((locomotive) -> {
            ObjectNode engine = mapper.createObjectNode();
            engine.put(ADDRESS, locomotive.getNumber());
            engine.put(IS_LONG_ADDRESS, locomotive.isLongAddress());
            engine.put(FORWARD, consist.getLocoDirection(locomotive));
            engine.put(POSITION, consist.getPosition(locomotive));
            engines.add(engine);
        });
        data.put(ID, consist.getConsistID());
        data.put(SIZE_LIMIT, consist.sizeLimit());
        return root;
    } else {
        // NOI18N
        throw new JsonException(404, Bundle.getMessage(locale, "ErrorObject", CONSIST, address.toString()));
    }
}
Also used : JsonException(jmri.server.json.JsonException) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Consist(jmri.Consist) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 100 with ArrayNode

use of com.fasterxml.jackson.databind.node.ArrayNode in project JMRI by JMRI.

the class JsonOperationsHttpService method getCars.

public ArrayNode getCars(Locale locale) {
    ArrayNode root = mapper.createArrayNode();
    CarManager.instance().getByIdList().forEach((rs) -> {
        root.add(this.utilities.getCar(locale, rs.getId()));
    });
    return root;
}
Also used : ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Aggregations

ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)277 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)167 JsonNode (com.fasterxml.jackson.databind.JsonNode)97 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)57 ArrayList (java.util.ArrayList)32 HashMap (java.util.HashMap)27 Test (org.junit.Test)25 Deployment (org.activiti.engine.test.Deployment)23 StringEntity (org.apache.http.entity.StringEntity)20 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)19 Cluster (org.apache.geode.tools.pulse.internal.data.Cluster)18 IOException (java.io.IOException)16 Map (java.util.Map)16 HttpPost (org.apache.http.client.methods.HttpPost)16 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)14 Task (org.activiti.engine.task.Task)13 GraphicInfo (org.activiti.bpmn.model.GraphicInfo)10 TextNode (com.fasterxml.jackson.databind.node.TextNode)8 JsonNodeFactory (com.fasterxml.jackson.databind.node.JsonNodeFactory)7 MissingNode (com.fasterxml.jackson.databind.node.MissingNode)7