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:controllers.impl.StandardApi.java

@Override
public F.Promise<Result> packageSearch(final String query) {
    final ObjectNode node = Json.newObject();
    final List<models.Package> packages = models.Package.searchByPartialName(query, 10);
    final ArrayNode resultsArray = node.putArray("results");
    for (final models.Package pkg : packages) {
        resultsArray.add(pkg.getName());
    }/*from   w w w .  j  a  va2s .  c o  m*/
    return F.Promise.pure(ok(node));
}

From source file:com.redhat.lightblue.util.JsonDoc.java

private static JsonNode modifyArrayNode(ArrayNode parentNode, JsonNode newValue, String last, Path p) {
    JsonNode oldValue;/*from w ww .j  av a 2  s .  c  om*/
    ArrayNode arr = (ArrayNode) parentNode;
    int index;
    try {
        index = Integer.valueOf(last);
    } catch (NumberFormatException e) {
        throw new IllegalArgumentException(UtilConstants.ERR_EXPECTED_ARRAY_INDEX + p);
    }
    int size = arr.size();
    while (size < index) {
        arr.addNull();
        size++;
    }
    if (index < 0) {
        index = size + index;
    }
    if (index < size && newValue != null) {
        oldValue = arr.get(index);
        arr.set(index, newValue);
    } else if (newValue == null) {
        oldValue = arr.get(index);
        arr.remove(index);
    } else {
        oldValue = null;
        arr.add(newValue);
    }
    return oldValue;
}

From source file:controllers.impl.StandardApi.java

@Override
public F.Promise<Result> environmentSearch(final String query) {
    final ObjectNode node = Json.newObject();
    final List<Environment> environments = Environment.searchByPartialName(query, 10);
    final ArrayNode resultsArray = node.putArray("results");
    for (final Environment env : environments) {
        resultsArray.add(env.getName());
    }//from   w w  w  .  j  a va 2  s . com
    return F.Promise.pure(ok(node));
}

From source file:org.apache.drill.optiq.DrillProjectRel.java

@Override
public int implement(DrillImplementor implementor) {
    int inputId = implementor.visitChild(this, 0, getChild());
    final ObjectNode project = implementor.mapper.createObjectNode();
    /*/*from w ww.  ja va 2s  .c  o  m*/
     * E.g. { op: "project", projections: [ { ref: "output.quantity", expr: "donuts.sales"} ]
     */
    project.put("op", "project");
    project.put("input", inputId);
    final ArrayNode transforms = implementor.mapper.createArrayNode();
    project.put("projections", transforms);
    for (Pair<RexNode, String> pair : projects()) {
        final ObjectNode objectNode = implementor.mapper.createObjectNode();
        transforms.add(objectNode);
        String expr = DrillOptiq.toDrill(getChild(), pair.left);
        objectNode.put("expr", expr);
        String ref = "output." + pair.right;
        //      String ref = pair.right;
        objectNode.put("ref", ref);
    }
    return implementor.add(project);
}

From source file:org.kiji.rest.TestKijiRestEntityId.java

@Test
public void testShouldCreateListsOfEntityIds() throws Exception {
    final TableLayoutDesc desc = KijiTableLayouts.getLayout("org/kiji/rest/layouts/rkf_hashprefixed.json");
    final KijiTableLayout layout = KijiTableLayout.newLayout(desc);
    final EntityIdFactory factory = EntityIdFactory.getFactory(layout);
    final byte[] rowKey = Bytes.toBytes(UNUSUAL_STRING_EID);
    final EntityId originalEid = factory.getEntityIdFromHBaseRowKey(rowKey);

    // test the creation of entity ids from raw hbase rowkey
    final KijiRestEntityId restEid1 = KijiRestEntityId.createFromUrl(
            String.format("hbase_hex=%s", new String(Hex.encodeHex(originalEid.getHBaseRowKey()))), layout);
    final KijiRestEntityId restEid2 = KijiRestEntityId.createFromUrl(
            String.format("hbase=%s", Bytes.toStringBinary(originalEid.getHBaseRowKey())), layout);

    final JsonNodeFactory jsonNodeFactory = new JsonNodeFactory(true);
    final JsonNode hbaseHexStringNode = jsonNodeFactory
            .textNode(String.format("hbase_hex=%s", new String(Hex.encodeHex(originalEid.getHBaseRowKey()))));
    final JsonNode hbaseBinaryStringNode = jsonNodeFactory
            .textNode(String.format("hbase_hex=%s", new String(Hex.encodeHex(originalEid.getHBaseRowKey()))));
    ArrayNode hbaseListNode = jsonNodeFactory.arrayNode();
    hbaseListNode.add(hbaseHexStringNode);
    hbaseListNode.add(hbaseBinaryStringNode);

    final List<KijiRestEntityId> restEidList1 = KijiRestEntityId.createListFromUrl(hbaseListNode.toString(),
            layout);//from w w  w .j  a  va2 s .c  om

    assertEquals(restEid1.resolve(layout), restEidList1.get(0).resolve(layout));
    assertEquals(restEid2.resolve(layout), restEidList1.get(1).resolve(layout));

    // test the creation of entity ids from various json strings
    final KijiRestEntityId restEid3 = KijiRestEntityId.createFromUrl("[\"Hello\",\"World\"]", layout);
    final List<KijiRestEntityId> restEidList3 = KijiRestEntityId.createListFromUrl("[[\"Hello\",\"World\"]]",
            layout);
    final KijiRestEntityId restEid4 = KijiRestEntityId.createFromUrl("[[],\"World\"]", layout);
    final List<KijiRestEntityId> restEidList4 = KijiRestEntityId
            .createListFromUrl("[[[],\"World\"],[\"Hello\",\"World\"]]", layout);

    assertEquals(restEid3.resolve(layout), restEidList3.get(0).resolve(layout));
    assertEquals(restEid4.getStringEntityId(), restEidList4.get(0).getStringEntityId());
    assertEquals(1, restEidList3.size());
    assertEquals(2, restEidList4.size());
}

From source file:org.onosproject.sdxl3.config.SdxParticipantsConfig.java

/**
 * Adds new BGP peer details to the configuration.
 *
 * @param peer BGP peer configuration entry
 *//* www.j  a  va 2 s . c o  m*/

public void addPeer(PeerConfig peer) {
    ObjectNode peerNode = JsonNodeFactory.instance.objectNode();

    if (peer.name().isPresent()) {
        peerNode.put(NAME, peer.name().get());
    }
    peerNode.put(IP, peer.ip().toString());
    peerNode.put(CONN_POINT,
            peer.connectPoint().elementId().toString() + "/" + peer.connectPoint().port().toString());
    peerNode.put(INTF_NAME, peer.interfaceName());

    ArrayNode peersArray = bgpPeers().isEmpty() ? initPeersConfiguration() : (ArrayNode) object.get(PEERS);
    peersArray.add(peerNode);
}

From source file:ws.wamp.jawampa.client.ClientConfiguration.java

public ClientConfiguration(boolean closeClientOnErrors, String authId,
        List<ClientSideAuthentication> authMethods, URI routerUri, String realm, boolean useStrictUriValidation,
        WampRoles[] clientRoles, int totalNrReconnects, int reconnectInterval,
        IWampConnectorProvider connectorProvider, IWampConnector connector, ObjectMapper objectMapper) {
    this.closeClientOnErrors = closeClientOnErrors;

    this.authId = authId;
    this.authMethods = authMethods;

    this.routerUri = routerUri;
    this.realm = realm;

    this.useStrictUriValidation = useStrictUriValidation;

    this.clientRoles = clientRoles;

    this.totalNrReconnects = totalNrReconnects;
    this.reconnectInterval = reconnectInterval;

    this.connectorProvider = connectorProvider;
    this.connector = connector;
    this.objectMapper = objectMapper;

    // Put the requested roles in the Hello message
    helloDetails = this.objectMapper.createObjectNode();
    helloDetails.put("agent", Version.getVersion());

    ObjectNode rolesNode = helloDetails.putObject("roles");
    for (WampRoles role : clientRoles) {
        ObjectNode roleNode = rolesNode.putObject(role.toString());
        if (role == WampRoles.Publisher) {
            ObjectNode featuresNode = roleNode.putObject("features");
            featuresNode.put("publisher_exclusion", true);
        } else if (role == WampRoles.Subscriber) {
            ObjectNode featuresNode = roleNode.putObject("features");
            featuresNode.put("pattern_based_subscription", true);
        } else if (role == WampRoles.Caller) {
            ObjectNode featuresNode = roleNode.putObject("features");
            featuresNode.put("caller_identification", true);
        }/*  ww  w  .j a v a2s.  c om*/
    }

    // Insert authentication data
    if (authId != null) {
        helloDetails.put("authid", authId);
    }
    if (authMethods != null && authMethods.size() != 0) {
        ArrayNode authMethodsNode = helloDetails.putArray("authmethods");
        for (ClientSideAuthentication authMethod : authMethods) {
            authMethodsNode.add(authMethod.getAuthMethod());
        }
    }
}

From source file:org.onlab.stc.Monitor.java

private void add(Dependency requirement, ArrayNode requirements) {
    ObjectNode rn = mapper.createObjectNode();
    rn.put("src", requirement.src().name()).put("dst", requirement.dst().name()).put("isSoft",
            requirement.isSoft());//from  w  w  w .  java  2 s  .  c  o m
    requirements.add(rn);
}

From source file:controllers.impl.StandardApi.java

@Override
public F.Promise<Result> hostclassSearch(final String query) {
    final ObjectNode node = Json.newObject();
    final List<models.Hostclass> hostclasses = models.Hostclass.searchByPartialName(query, 10);
    final ArrayNode resultsArray = node.putArray("results");
    for (final models.Hostclass hostclass : hostclasses) {
        resultsArray.add(hostclass.getName());
    }/* w  w  w  . ja va  2s.c  o  m*/
    return F.Promise.pure(ok(node));
}

From source file:controllers.impl.StandardApi.java

@Override
public F.Promise<Result> getStages(final String envName) {
    final Environment environment = Environment.getByName(envName);
    if (environment == null) {
        return F.Promise.pure(notFound());
    }//w w w . ja  va  2 s .  com

    final ObjectNode node = Json.newObject();
    final ArrayNode resultsArray = node.putArray("results");
    for (final Stage stage : environment.getStages()) {
        resultsArray.add(stage.getName());
    }
    return F.Promise.pure(ok(node));
}