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.controllers.MobileApp.java

/**
 * ?//w w w. j a  va  2  s  .  co  m
 */
@Transactional
public static Result getIntroImgs(String from) {
    List<IntroImg> list = MobileService.getIntroImgList(from);

    MobileResult result = MobileResult.success();
    result.setToField("introImgList", list);

    // shenteng ??
    ObjectNode oldNode = Json.newObject();
    ArrayNode array = Json.newObject().arrayNode();
    for (IntroImg introImg : list) {
        array.add(introImg.getImgUrl());
    }
    oldNode.set("imgs", array);
    result.setObjectNode(oldNode);

    return result.getResult();
}

From source file:com.ibm.watson.catalyst.corpus.tfidf.CorpusTfidf.java

public static ObjectNode getCorpusTfidfs(TermCorpus c) {
    ObjectNode root = MAPPER.createObjectNode();
    root.put("corpus-name", "Health");
    ArrayNode root2 = MAPPER.createArrayNode();
    int index = 0;
    for (TermDocument d : c.getDocuments()) {
        root2.add(printGoodWords(d, c));
        if (++index % 100 == 0)
            System.out.print(index + " documents processed.\r");
    }//from  www . j ava2 s .c  om
    System.out.println(index + " documents processed.");
    root.set("documents", root2);
    return root;
}

From source file:io.wcm.caravan.pipeline.extensions.hal.filter.ReportHalResourceFilters.java

private static HalResource createReport(HalPath halPath, HalResource hal, List<String> errors) {

    HalResource filterReport = new HalResource(hal.getLink().getHref());
    filterReport.getModel().put("halPath", halPath.toString());
    ArrayNode errorContainer = filterReport.getModel().putArray("errors");
    for (String error : errors) {
        errorContainer.add(error);
    }/*from w w w  .java  2  s .  co  m*/

    filterReport.getModel().set("copy", hal.getModel().deepCopy());

    return filterReport;

}

From source file:neo4play.RelationshipService.java

private static JsonNode buildStatements(String query) {
    ObjectNode statement = Json.newObject();
    statement.put("statement", query);
    ArrayNode statementList = JsonNodeFactory.instance.arrayNode();
    statementList.add(statement);
    ObjectNode statements = Json.newObject();
    statements.put("statements", statementList);
    return statements;
}

From source file:com.github.fge.jsonschema.process.JsonPatch.java

private static JsonNode buildReport(final ProcessingReport report) {
    final ArrayNode ret = JacksonUtils.nodeFactory().arrayNode();
    for (final ProcessingMessage message : report)
        ret.add(message.asJson());
    return ret;/*from w  w w . j av  a2  s.c o m*/
}

From source file:net.pterodactylus.sone.web.ajax.GetLikesAjaxPage.java

/**
 * Creates a JSON array (containing the IDs and the nice names) from the
 * given Sones, after sorting them by name.
 *
 * @param sones/*from  ww  w.  ja v a  2 s . c  om*/
 *            The Sones to convert to an array
 * @return The Sones, sorted by name
 */
private static JsonNode getSones(Set<Sone> sones) {
    ArrayNode soneArray = new ArrayNode(instance);
    for (Sone sone : FluentIterable.from(sones).toSortedList(NICE_NAME_COMPARATOR)) {
        soneArray.add(
                new ObjectNode(instance).put("id", sone.getId()).put("name", SoneAccessor.getNiceName(sone)));
    }
    return soneArray;
}

From source file:easyrpc.client.serialization.jsonrpc.JSONCaller.java

private static void addType(Object value, ArrayNode arr) {
    switch (value.getClass().getName()) {
    case "java.lang.Integer":
    case "int":
        arr.add((Integer) value);
        break;//from ww w  .  ja  va  2s  . co m
    case "java.lang.Long":
    case "long":
        arr.add((Long) value);
        break;
    case "java.lang.Character":
    case "char":
        arr.add((java.lang.Character) value);
        break;
    case "java.lang.Void":
    case "void":
        throw new IllegalArgumentException("A parameter cannot be of void type");
    case "java.lang.Float":
    case "float":
        arr.add((Float) value);
        break;
    case "java.lang.Double":
    case "double":
        arr.add((Double) value);
        break;
    case "java.lang.String":
        arr.add((String) value);
        break;
    default:
        // map an object
        arr.add(MAPPER.valueToTree(value));
    }
}

From source file:com.almende.arum.RESTApplication.java

/**
 * Inits the./*w  w  w.  j  a  v  a  2  s .c  o  m*/
 */
public static void init() {
    Servlet servlet = new org.apache.wink.server.internal.servlet.RestServlet();
    ObjectNode params = JOM.createObjectNode();
    ArrayNode initParams = JOM.createArrayNode();
    ObjectNode param = JOM.createObjectNode();
    param.put("key", "javax.ws.rs.Application");
    param.put("value", RESTApplication.class.getName());
    initParams.add(param);
    params.set("initParams", initParams);

    JettyLauncher launcher = new JettyLauncher();
    try {

        launcher.add(servlet, new URI("/rs/"), params);
        launcher.addFilter("com.thetransactioncompany.cors.CORSFilter", "/*");

    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
}

From source file:mobile.util.MobileVOUtil.java

/**
 * VOsetObjectNode?//from ww  w  .  j  a va2s .c o  m
 * 
 * @param node ObjectNode
 * @param fieldName ??
 * @param c MobileVO?
 */
public static void setToField(ObjectNode node, String fieldName, Collection<?> c) {
    if (null == node) {
        throw new IllegalArgumentException("node is null");
    }

    ArrayNode arrayNode = Json.newObject().arrayNode();

    if (CollectionUtils.isNotEmpty(c)) {
        for (Object vo : c) {
            if (vo instanceof MobileVO) {
                arrayNode.add(MobileVOUtil.toJson((MobileVO) vo));
            } else {
                arrayNode.add(Json.toJson(vo));
            }
        }
    }

    node.set(fieldName, arrayNode);
}

From source file:org.teavm.flavour.json.test.TeaVMJSONRunner.java

public static final JsonNode convert(JsonNodeFactory nf, Node node) {
    if (node.isNull()) {
        return nf.nullNode();
    } else if (node.isBoolean()) {
        BooleanNode booleanNode = (BooleanNode) node;
        return nf.booleanNode(booleanNode.getValue());
    } else if (node.isNumber()) {
        NumberNode numberNode = (NumberNode) node;
        if (numberNode.isInt()) {
            return nf.numberNode(numberNode.getIntValue());
        } else {/*from   w w  w  . ja va 2s .  c  o  m*/
            return nf.numberNode(numberNode.getValue());
        }
    } else if (node.isString()) {
        StringNode stringNode = (StringNode) node;
        return nf.textNode(stringNode.getValue());
    } else if (node.isArray()) {
        ArrayNode result = nf.arrayNode();
        org.teavm.flavour.json.tree.ArrayNode source = (org.teavm.flavour.json.tree.ArrayNode) node;
        for (int i = 0; i < source.size(); ++i) {
            result.add(convert(nf, source.get(i)));
        }
        return result;
    } else if (node.isObject()) {
        com.fasterxml.jackson.databind.node.ObjectNode result = nf.objectNode();
        ObjectNode objectNode = (ObjectNode) node;
        for (String key : objectNode.allKeys()) {
            result.replace(key, convert(nf, objectNode.get(key)));
        }
        return result;
    } else {
        throw new IllegalArgumentException("Can't convert this JSON node");
    }
}