Example usage for com.fasterxml.jackson.databind.node ObjectNode put

List of usage examples for com.fasterxml.jackson.databind.node ObjectNode put

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind.node ObjectNode put.

Prototype

public ObjectNode put(String paramString1, String paramString2) 

Source Link

Usage

From source file:controllers.api.v1.AdvSearch.java

public static Result getDatasetFields() {
    ObjectNode result = Json.newObject();
    String tables = request().getQueryString("tables");
    result.put("status", "ok");
    result.set("fields", Json.toJson(AdvSearchDAO.getFields(tables)));

    return ok(result);
}

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

private static boolean fillWithData(final ObjectNode node, final String onSuccess, final String onFailure,
        final String raw) throws IOException {
    try {//from   w w w.  java 2 s  . c  om
        node.put(onSuccess, NODE_READER.fromReader(new StringReader(raw)));
        return false;
    } catch (JsonProcessingException e) {
        node.put(onFailure, ParseError.build(e, raw.contains("\r\n")));
        return true;
    }
}

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

/**
 * Creates a JSON object that contains all options that are currently in
 * effect for the given Sone (or overall, if the given Sone is {@code null}
 * )./*  w ww.j  ava  2 s . c om*/
 *
 * @param currentSone
 *            The current Sone (may be {@code null})
 * @return The current options
 */
private static JsonNode createJsonOptions(Sone currentSone) {
    ObjectNode options = new ObjectNode(instance);
    if (currentSone != null) {
        options.put("ShowNotification/NewSones",
                currentSone.getOptions().getBooleanOption("ShowNotification/NewSones").get());
        options.put("ShowNotification/NewPosts",
                currentSone.getOptions().getBooleanOption("ShowNotification/NewPosts").get());
        options.put("ShowNotification/NewReplies",
                currentSone.getOptions().getBooleanOption("ShowNotification/NewReplies").get());
    }
    return options;
}

From source file:util.APICall.java

public static JsonNode createResponse(ResponseType type) {
    ObjectNode jsonData = Json.newObject();
    switch (type) {
    case SUCCESS:
        jsonData.put("success", "Success!");
        break;//  w  ww.  ja  va 2 s  .  c  o m
    case GETERROR:
        jsonData.put("error", "Cannot get data from server");
        break;
    case SAVEERROR:
        jsonData.put("error", "Cannot be saved. The data must be invalid!");
        break;
    case DELETEERROR:
        jsonData.put("error", "Cannot be deleted on server");
        break;
    case RESOLVEERROR:
        jsonData.put("error", "Cannot be resolved on server");
        break;
    case TIMEOUT:
        jsonData.put("error", "No response/Timeout from server");
        break;
    case CONVERSIONERROR:
        jsonData.put("error", "Conversion error");
        break;
    default:
        jsonData.put("error", "Unknown errors");
        break;
    }
    return jsonData;
}

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);/*from  ww w  .  j  a v a 2  s  .c  o  m*/
    }

    return jsonArray;
}

From source file:controllers.user.UserAvatarApp.java

/**
 * ?email?id/*from w w  w  .  j  ava2 s  .  com*/
 * 
 * @return
 */
@Transactional
public static Result queryIdByEmail() {
    JsonNode jsonNode = getJson();
    ObjectNodeResult result = new ObjectNodeResult();
    Iterator<JsonNode> emails = jsonNode.get("emails").elements();
    List<String> s = new ArrayList<String>();
    while (emails.hasNext()) {
        String email = emails.next().asText();
        s.add(email);
    }
    List<User> list = User.queryIdByEmail(s);
    ObjectNode objectNode = Json.newObject();
    for (User user : list) {
        objectNode.put(user.email, user.id);
    }
    result.put("user", objectNode);
    return ok(result.getObjectNode());
}

From source file:org.opendaylight.sfc.sbrest.json.ExporterUtil.java

protected static ObjectNode getSffSfDataPlaneLocatorObjectNode(SffSfDataPlaneLocator sffSfDpl) {
    if (sffSfDpl == null) {
        return null;
    }/*  ww w . j a  v  a  2s .c o  m*/

    ObjectMapper mapper = new ObjectMapper();
    ObjectNode sffSfDplNode = mapper.createObjectNode();

    if (sffSfDpl.getSfDplName() != null) {
        sffSfDplNode.put(_SF_DPL_NAME, sffSfDpl.getSfDplName().getValue());
    }

    if (sffSfDpl.getSffDplName() != null) {
        sffSfDplNode.put(_SFF_DPL_NAME, sffSfDpl.getSffDplName().getValue());
    }

    return sffSfDplNode;
}

From source file:com.wegas.log.neo4j.Neo4jPlayerReply.java

/**
 * Creates a new Number node, with all the necessary properties.
 *
 * @param player the player data//from   w  w  w .j  av a  2 s  . c om
 * @param name   the variable name
 * @param value  the actual variable value
 * @return a node object
 * @throws JsonProcessingException
 */
private static ObjectNode createJsonNode(Player player, String name, double value)
        throws JsonProcessingException {
    ObjectNode jsonObject = objectMapper.createObjectNode();

    jsonObject.put("type", TYPE.NUMBER.toString());
    jsonObject.put("playerId", player.getId());
    jsonObject.put("teamId", player.getTeamId());
    jsonObject.put("gameId", player.getGameId());
    jsonObject.put("name", player.getName());
    jsonObject.put("starttime", (new Date()).getTime());
    jsonObject.put("variable", name);
    jsonObject.put("number", value);
    jsonObject.put("logID", player.getGameModel().getProperties().getLogID());
    return jsonObject;
}

From source file:com.ikanow.aleph2.data_model.utils.JsonUtils.java

/** Takes a tuple expressed as LinkedHashMap<String, Object> (by convention the Objects are primitives, JsonNode, or POJO), and where one of the objects
 *  is a JSON representation of the original object and creates an object by folding them all together
 *  Note the other fields of the tuple take precedence over the JSON
 * @param in - the tuple/*from  w  w w  . j av  a  2s .c  o  m*/
 * @param mapper - the Jackson object mapper
 * @param json_field - optional fieldname of the string representation of the JSON - if not present then the last field is used (set to eg "" if there is no base object)
 * @return
 */
public static JsonNode foldTuple(final LinkedHashMap<String, Object> in, final ObjectMapper mapper,
        final Optional<String> json_field) {
    try {
        // (do this imperatively to handle the "last element can be the base object case"
        final Iterator<Map.Entry<String, Object>> it = in.entrySet().iterator();
        ObjectNode acc = mapper.createObjectNode();
        while (it.hasNext()) {
            final Map.Entry<String, Object> kv = it.next();
            if ((json_field.isPresent() && kv.getKey().equals(json_field.get()))
                    || !json_field.isPresent() && !it.hasNext()) {
                acc = (ObjectNode) ((ObjectNode) mapper.readTree(kv.getValue().toString())).setAll(acc);
            } else {
                final ObjectNode acc_tmp = acc;
                Patterns.match(kv.getValue()).andAct().when(String.class, s -> acc_tmp.put(kv.getKey(), s))
                        .when(Long.class, l -> acc_tmp.put(kv.getKey(), l))
                        .when(Integer.class, l -> acc_tmp.put(kv.getKey(), l))
                        .when(Boolean.class, b -> acc_tmp.put(kv.getKey(), b))
                        .when(Double.class, d -> acc_tmp.put(kv.getKey(), d))
                        .when(JsonNode.class, j -> acc_tmp.set(kv.getKey(), j))
                        .when(Float.class, f -> acc_tmp.put(kv.getKey(), f))
                        .when(BigDecimal.class, f -> acc_tmp.put(kv.getKey(), f))
                        .otherwise(x -> acc_tmp.set(kv.getKey(), BeanTemplateUtils.toJson(x)));
            }
        }
        return acc;
    } catch (Exception e) {
        throw new RuntimeException(e);
    } // (convert to unchecked exception)
}

From source file:com.github.khazrak.jdocker.utils.Filters.java

public static String encodeFilters(Map<String, String> filters) {
    ObjectMapper mapper = new ObjectMapper();
    String result = null;/*w ww.  ja v  a  2  s .com*/
    ObjectNode objectNode = mapper.createObjectNode();
    if (!filters.keySet().isEmpty()) {
        for (Map.Entry<String, String> s : filters.entrySet()) {
            objectNode.putObject(s.getKey()).put(s.getValue(), true);
        }
    }

    try {
        result = URLEncoder.encode(objectNode.toString(), StandardCharsets.UTF_8.toString());
    } catch (UnsupportedEncodingException e) {
        logger.error("Error encoding filtersMap", e);
    }
    return result;
}