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:mobile.service.RNSService.java

/**
 * ?/*from   w ww .  j  a v  a2 s  . c om*/
 *
 * @param serviceId ?Id
 * @param index     ??0
 * @return
 */
public static ServiceResult deleteServicePic(Long serviceId, List<Integer> index) {
    Service service = Service.queryServiceById(serviceId);
    if (null == service) {
        return ServiceResult.error("1008", "??");
    }
    if (!service.getOwner().getId().equals(MobileUtil.getCurrentUser().getId())) {
        return ServiceResult.error("1004", "???");
    }

    // ?Json
    Set<AttachOfService> caseAttachs = service.getCaseAttachs();
    ArrayNode attachArray = Json.newObject().arrayNode();
    int counter = 0;
    List<Long> deleteAttachIdList = new ArrayList<Long>();
    for (AttachOfService attachOfService : caseAttachs) {
        if (index.contains(counter)) {
            deleteAttachIdList.add(attachOfService.id);
        } else {
            ObjectNode attachNode = Json.newObject();
            attachNode.put("attachId", attachOfService.id);
            attachArray.add(attachNode);
        }

        counter++;
    }
    Attach.deleteByIds(deleteAttachIdList, AttachOfService.class);

    ObjectNode data = Json.newObject();
    data.put("id", serviceId);
    data.set("attachs", attachArray);

    ServiceResult deleteResult = createOrUpdateService(data, null);
    if (!deleteResult.isSuccess()) {
        return deleteResult;
    }

    return ServiceResult.success();
}

From source file:com.nebhale.jsonpath.internal.parser.RecoveringPathParserTest.java

@Test
public void wildcardIndex() {
    JsonNode nodeBook = NODE.get("store").get("book");
    ArrayNode expected = JsonNodeFactory.instance.arrayNode();
    expected.add(nodeBook.get(0));
    expected.add(nodeBook.get(1));// w w  w.j a va  2 s.  co  m
    expected.add(nodeBook.get(2));
    expected.add(nodeBook.get(3));

    ParserResult result = this.parser.parse("$.store.book[*]");

    assertNoProblems(result);
    assertEquals(expected, result.getPathComponent().get(NODE));
}

From source file:mobile.service.RNSService.java

/**
 * //w  w w  .  ja  v a  2 s .c  o  m
 *
 * @param requireId Id
 * @param index     ??0
 * @return
 */
public static ServiceResult deleteRequireAttachment(Long requireId, List<Integer> index) {
    Require require = Require.queryRequireById(requireId);
    if (null == require) {
        return ServiceResult.error("1007", "?");
    }
    if (!require.getOwner().getId().equals(MobileUtil.getCurrentUser().getId())) {
        return ServiceResult.error("1003", "??");
    }

    Set<AttachOfRequire> caseAttachs = require.getCaseAttachs();

    // ?Json
    ArrayNode attachArray = Json.newObject().arrayNode();
    int counter = 0;
    List<Long> deleteAttachIdList = new ArrayList<Long>();
    for (AttachOfRequire attachOfService : caseAttachs) {
        if (index.contains(counter)) {
            deleteAttachIdList.add(attachOfService.id);
        } else {
            ObjectNode attachNode = Json.newObject();
            attachNode.put("attachId", attachOfService.id);
            attachArray.add(attachNode);
        }

        counter++;
    }
    Attach.deleteByIds(deleteAttachIdList, AttachOfRequire.class);

    ObjectNode data = Json.newObject();
    data.put("id", requireId);
    data.set("attachs", attachArray);

    ServiceResult deleteResult = createOrUpdateRequire(data, null);
    if (!deleteResult.isSuccess()) {
        return deleteResult;
    }

    return ServiceResult.success();
}

From source file:com.redhat.lightblue.crud.CRUDFindRequest.java

/**
 * Populates an object node with the JSON representation of this
 *//*from   w w w  .j av  a  2 s.co  m*/
public void toJson(JsonNodeFactory factory, ObjectNode node) {
    if (query != null) {
        node.set("query", query.toJson());
    }
    if (projection != null) {
        node.set("projection", projection.toJson());
    }
    if (sort != null) {
        node.set("sort", sort.toJson());
    }
    if (from != null && to != null) {
        ArrayNode arr = factory.arrayNode();
        arr.add(from);
        arr.add(to);
        node.set("range", arr);
    }
}

From source file:org.modeshape.web.jcr.rest.model.RestWorkspaces.java

@Override
public ObjectNode toJSON(Json json) {
    ObjectNode result = json.newObject();
    ArrayNode workspaces = result.putArray("workspaces");
    for (Workspace workspace : this.workspaces) {
        workspaces.add(workspace.toJSON(json));
    }//from  w w w. j av a 2  s  . c om
    return result;
}

From source file:com.rusticisoftware.tincan.StatementsResult.java

@Override
public ObjectNode toJSONNode(TCAPIVersion version) {
    ObjectNode node = Mapper.getInstance().createObjectNode();

    if (this.getStatements() != null) {
        ArrayNode statementsNode = Mapper.getInstance().createArrayNode();
        for (Statement statement : this.getStatements()) {
            statementsNode.add(statement.toJSONNode(version));
        }/*from   ww  w . ja v  a2  s.c  o m*/
        node.put("statements", statementsNode);
    }

    if (this.getMoreURL() != null) {
        node.put("more", this.getMoreURL());
    }
    return node;
}

From source file:com.vaporwarecorp.mirror.feature.greet.GreetManagerImpl.java

@Override
public String getJsonValues() {
    final ArrayNode formItems = createArrayNode();
    for (int i = 0; i < mWelcomes.size(); i++) {
        formItems.add(createTextNode("welcome", mWelcomes.get(i)).put("goodbye", mGoodbyes.get(i)));
    }//from  w ww . j  av a 2  s.c  om
    return createJsonNode("formItems", formItems).toString();
}

From source file:org.opendaylight.sfc.sbrest.provider.task.SbRestRspTaskTest.java

private ObjectNode buildRenderedServicePathTopNode() {
    ObjectNode topNode = mapper.createObjectNode();

    ObjectNode rspNode = mapper.createObjectNode();

    ArrayNode rspArrayNode = mapper.createArrayNode();
    rspArrayNode.add(rspNode);

    topNode.put(RspExporterFactory._RENDERED_SERVICE_PATH, rspArrayNode);
    return topNode;
}

From source file:org.modeshape.web.jcr.rest.model.RestQueryResult.java

@Override
public ObjectNode toJSON(Json json) {
    ObjectNode result = json.newObject();
    if (!columns.isEmpty()) {
        ObjectNode columnsNode = result.putObject("columns");
        for (String column : columns.keySet()) {
            columnsNode.put(column, columns.get(column));
        }// w w  w . ja v a2s.c  o  m
    }
    if (!rows.isEmpty()) {
        ArrayNode rows = result.putArray("rows");
        for (RestRow row : this.rows) {
            rows.add(row.toJSON(json));
        }
    }
    return result;
}

From source file:org.opendaylight.sfc.sbrest.provider.task.SbRestRspTaskTest.java

private ObjectNode buildRenderedServicePathObjectNode1() {
    ObjectNode topNode = mapper.createObjectNode();

    ObjectNode rspNode = mapper.createObjectNode();
    rspNode.put(RspExporterFactory._NAME, RSP_NAME.getValue());

    ArrayNode rspArrayNode = mapper.createArrayNode();
    rspArrayNode.add(rspNode);

    topNode.put(RspExporterFactory._RENDERED_SERVICE_PATH, rspArrayNode);
    return topNode;
}