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:io.fabric8.profiles.ProfilesHelpers.java

public static JsonNode merge(JsonNode target, JsonNode source) {
    if (target == null) {
        return source;
    }/*  www  . ja v a 2  s.  c  o m*/
    if (target.isArray() && source.isArray()) {
        // we append values from the source.
        ArrayNode copy = (ArrayNode) target.deepCopy();
        for (JsonNode n : source) {
            if ((n.isTextual() && DELETED.equals(n.textValue()))) {
                copy = JsonNodeFactory.instance.arrayNode();
            } else {
                copy.add(n);
            }
        }
        return copy;
    } else if (target.isObject() && source.isObject()) {
        ObjectNode copy = (ObjectNode) target.deepCopy();
        if (source.get(DELETED) != null) {
            copy = JsonNodeFactory.instance.objectNode();
        } else {
            Iterator<String> iterator = source.fieldNames();
            while (iterator.hasNext()) {
                String key = iterator.next();
                if (!DELETED.equals(key)) {
                    JsonNode value = source.get(key);
                    if ((value.isTextual() && DELETED.equals(value.textValue()))) {
                        copy.remove(key);
                    } else {
                        JsonNode original = target.get(key);
                        value = merge(original, value);
                        copy.set(key, value);
                    }
                }
            }
        }
        return copy;
    } else {
        return source;
    }

}

From source file:com.flipkart.zjsonpatch.JsonDiff.java

private static ArrayNode getJsonNodes(List<Diff> diffs) {
    JsonNodeFactory FACTORY = JsonNodeFactory.instance;
    final ArrayNode patch = FACTORY.arrayNode();
    for (Diff diff : diffs) {
        ObjectNode jsonNode = getJsonNode(FACTORY, diff);
        patch.add(jsonNode);
    }//from   ww w . j a v a 2 s. c o m
    return patch;
}

From source file:com.qualixium.executor.command.CommandHelper.java

public static JsonNode getJsonNodeFromCommandsModel(DefaultTableModel model) {
    ArrayNode jsonArray = MAPPER.createArrayNode();

    for (int i = 0; i < model.getRowCount(); i++) {
        ObjectNode jsonNode = MAPPER.createObjectNode();

        String name = (String) model.getValueAt(i, 0);
        String command = ((String) model.getValueAt(i, 1)).replace("\\", "\\\\");

        jsonNode.put(model.getColumnName(0), name);
        jsonNode.put(model.getColumnName(1), command);

        jsonArray.add(jsonNode);
    }// ww w. jav  a 2  s . c  o  m

    return jsonArray;
}

From source file:models.service.reminder.RemindService.java

/**
 * ?Json???,??,//from  w w  w. j a va2  s . c  o  m
 * 
 * @param user ?
 * @param items ?items
 * 
 * @return ??Json
 */
public static JsonNode getCfgJsonWithDefault(User user, Item[] items) {
    JsonNode parse = null;
    String cfg = user.safetyReminderConfig;
    if (StringUtils.isNotBlank(cfg)) {
        parse = Json.parse(cfg);
    }
    ObjectNode result = Json.newObject();

    // ?
    for (Item item : items) {
        if (!item.isEnable) {
            continue;
        }

        String itemVal = item.getVal();
        if (null == parse || !parse.hasNonNull(itemVal)) {
            ArrayNode options = Json.newObject().arrayNode();
            if (ArrayUtils.isNotEmpty(item.getDefaultOptions())) {
                for (Option option : item.getDefaultOptions()) {
                    options.add(option.getVal());
                }
            }
            result.set(itemVal, options);
        } else {
            result.set(itemVal, parse.get(itemVal));
        }
    }

    return result;
}

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

private static JsonNode toJson(Collection obj) {
    ArrayNode node = JsonNodeFactory.instance.arrayNode();
    for (Object x : obj) {
        node.add(toJson(x));
    }// w  w  w. jav a  2 s .c  o m
    return node;
}

From source file:mobile.service.SelfInfoService.java

/**
 * ??/*from  w  w w.ja va  2 s. com*/
 * 
 * @param newEduExp ?Json
 */
public static ServiceResult addEducationExp(JsonNode newEduExp) {
    User user = User.getFromSession(Context.current().session());
    Expert expert = Expert.findByUserId(user.id);

    ArrayNode eduExpArrayNode = null;
    if (null == expert || StringUtils.isBlank(expert.educationExp)) {
        eduExpArrayNode = Json.newObject().arrayNode();
    } else {
        eduExpArrayNode = (ArrayNode) Json.parse(expert.educationExp);
    }
    eduExpArrayNode.add(newEduExp);

    ObjectNode eduExpNode = Json.newObject();
    eduExpNode.set("educationExp", eduExpArrayNode);
    ObjectNodeResult objectNodeResult = Expert.saveExpertByJson(Context.current().session(), eduExpNode);

    return ServiceResult.create(objectNodeResult);
}

From source file:controllers.ConfigurationApplication.java

public static Result uploadPuppetFile() {
    String callBackUrl = GoogleComputeEngineAuthImpl.getCallBackURL(request());
    ObjectNode returnMessage = Json.newObject();
    try {/*w  ww .  j a va  2 s  .  c om*/
        String result = GoogleAuthenticationService.authenticate(callBackUrl, null);
        if (result != null) {
            return redirect(result);
        }

        ArrayNode fileList = new ArrayNode(JsonNodeFactory.instance);
        for (Http.MultipartFormData.FilePart filePart : request().body().asMultipartFormData().getFiles()) {
            ConfigurationService.uploadPuppetFile(PuppetConfiguration.PUPPET_FILE, filePart.getFilename(),
                    filePart.getFile());
            fileList.add(filePart.getFilename());
        }
        returnMessage.set("result", Json.newObject().textNode("ok"));
        returnMessage.set("files", fileList);
        return ok(returnMessage);
    } catch (GoogleComputeEngineException e) {
        returnMessage.set("result", Json.newObject().textNode("error"));
        returnMessage.set("message", Json.newObject().textNode(e.getMessage()));
        return ok(returnMessage);
    } catch (PuppetConfigurationException e) {
        returnMessage.set("result", Json.newObject().textNode("error"));
        returnMessage.set("message", Json.newObject().textNode(e.getMessage()));
        return ok(returnMessage);
    }
}

From source file:mobile.service.UserService.java

/**
 * ?//from w  w w. ja va  2s .c  o  m
 *
 * @return
 */
public static List<CommonVO> getIndustryTagList() {
    List<SkillTag> skillTags = SkillTag.getCategoryTag(true);
    List<CommonVO> list = new ArrayList<CommonVO>();

    if (skillTags.size() > 0) {
        for (SkillTag tags : skillTags) {
            CommonVO commonVO = CommonVO.create();
            commonVO.set("id", tags.id);
            commonVO.set("tagName", tags.tagName);

            List<Attach> attachList = new AttachOfIndustry().queryByAttachId(tags.getId());

            ArrayNode arrayNode = Json.newObject().arrayNode();
            for (Attach attach : attachList) {
                ObjectNode attachNode = Json.newObject();
                attachNode.put("filename", attach.fileName);
                attachNode.put("url", Assets.at(attach.path));
                arrayNode.add(attachNode);
            }
            commonVO.set("attachs", arrayNode);

            list.add(commonVO);
        }
    }

    return list;
}

From source file:com.msopentech.odatajclient.testservice.utils.Commons.java

public static InputStream getLinksAsJSON(final String entitySetName,
        final Map.Entry<String, Collection<String>> link) throws IOException {
    final ObjectNode links = new ObjectNode(JsonNodeFactory.instance);
    links.put(JSON_ODATAMETADATA_NAME, ODATA_METADATA_PREFIX + entitySetName + "/$links/" + link.getKey());

    final ArrayNode uris = new ArrayNode(JsonNodeFactory.instance);

    for (String uri : link.getValue()) {
        final String absoluteURI;
        if (URI.create(uri).isAbsolute()) {
            absoluteURI = uri;//  w w w .j  a v a 2s  .  co m
        } else {
            absoluteURI = DEFAULT_SERVICE_URL + uri;
        }
        uris.add(new ObjectNode(JsonNodeFactory.instance).put("url", absoluteURI));
    }

    if (uris.size() == 1) {
        links.setAll((ObjectNode) uris.get(0));
    } else {
        links.set("value", uris);
    }

    return IOUtils.toInputStream(links.toString());
}

From source file:controllers.user.UserSettingApp.java

@Transactional
public static Result queryConnectedSNS() {
    User user = User.getFromSession(session());
    Map<String, UserOAuth> userOAuthMap = UserOAuthService.getValidByUserId(user.id);
    ArrayNode sns = Json.newObject().arrayNode();
    for (Map.Entry<String, UserOAuth> e : userOAuthMap.entrySet()) {
        sns.add(e.getKey());
    }//from   ww  w . j  ava 2  s  . co m
    ObjectNodeResult result = new ObjectNodeResult();
    result.put("sns", sns);
    return ok(result.getObjectNode());
}