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:net.hamnaberg.json.Query.java

public static Query create(Target target, String rel, Optional<String> prompt, Optional<String> name,
        Iterable<Property> data) {
    ObjectNode obj = JsonNodeFactory.instance.objectNode();
    obj.put("href", target.toString());
    if (target.isURITemplate()) {
        obj.put("encoding", "uri-template");
    }//from   w  w  w  .j  a  v a2 s. co m
    obj.put("rel", rel);
    prompt.ifPresent(value -> obj.put("prompt", value));
    name.ifPresent(value -> obj.put("name", value));
    if (!Iterables.isEmpty(data)) {
        obj.set("data", StreamSupport.stream(data.spliterator(), false).map(Extended::asJson)
                .collect(JsonNodeFactory.instance::arrayNode, ArrayNode::add, ArrayNode::addAll));
    }
    return new Query(obj);
}

From source file:controllers.FormsController.java

private static JsonNode generateFieldFromProperty(String fieldName) {
    Properties props = getPropertyFile();
    ObjectNode formElememt = Json.newObject();

    formElememt.put("name", fieldName);
    formElememt.put("label", props.getProperty(fieldName + "_label"));
    formElememt.put("type", props.getProperty(fieldName + "_type"));

    if (formElememt.get("type").asText().equalsIgnoreCase("list")) {
        try {/*from   w w  w . j  a v  a  2 s . c o  m*/
            Class<?> cl = Class.forName("models.fixed." + Character.toString(fieldName.charAt(0)).toUpperCase()
                    + fieldName.substring(1));
            List<?> l = Ebean.find(cl).findList();
            formElememt.put("options", Json.toJson(l));
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(FormsController.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    ObjectNode validations = Json.newObject();
    validations.put("required", props.getProperty(fieldName + "_validations_required"));
    validations.put("pattern", props.getProperty(fieldName + "_validations_pattern"));
    formElememt.put("validations", validations);

    ObjectNode messages = Json.newObject();
    messages.put("invalid", props.getProperty(fieldName + "_validationmessages_invalid"));
    messages.put("required", props.getProperty(fieldName + "_validationmessages_required"));
    messages.put("pattern", props.getProperty(fieldName + "_validationmessages_pattern"));
    formElememt.put("validationMessages", messages);

    return Json.toJson(formElememt);
}

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

public static Result getFlowApplicationCodes() {
    ObjectNode result = Json.newObject();
    result.put("status", "ok");
    result.set("appcodes", Json.toJson(AdvSearchDAO.getFlowApplicationCodes()));

    return ok(result);
}

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

public static Result getJobNames() {
    ObjectNode result = Json.newObject();
    result.put("status", "ok");
    result.set("jobNames", Json.toJson(AdvSearchDAO.getFlowJobNames()));

    return ok(result);
}

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

public static Result getDatasetSources() {
    ObjectNode result = Json.newObject();

    result.put("status", "ok");
    result.set("sources", Json.toJson(AdvSearchDAO.getDatasetSources()));

    return ok(result);
}

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

public static Result getDatasetScopes() {
    ObjectNode result = Json.newObject();

    result.put("status", "ok");
    result.set("scopes", Json.toJson(AdvSearchDAO.getDatasetScopes()));

    return ok(result);
}

From source file:com.pros.jsontransform.plugin.sort.ArraySortByAvgAge.java

public static void sort(final ArrayNode arrayNode, final JsonNode sortNode, final ObjectTransformer transformer)
        throws ObjectTransformerException {
    // target array does not contain age information so
    // we need to use the source array from transformer context to perform the sort
    ArrayNode sourceArray = (ArrayNode) transformer.getSourceNode();

    // move source and target array nodes to sorting array
    int size = arrayNode.size();
    ArrayList<JsonNode> sortingArray = new ArrayList<JsonNode>(arrayNode.size());
    for (int i = 0; i < size; i++) {
        ObjectNode sortingElement = transformer.mapper.createObjectNode();
        sortingElement.put("source", sourceArray.get(i));
        sortingElement.put("target", arrayNode.remove(0));
        sortingArray.add(sortingElement);
    }//  www.ja  v a  2  s . c om

    // sort array
    sortingArray.sort(new AvgAgeComparator(sortNode));

    // move nodes back to targetArray
    for (int i = 0; i < sortingArray.size(); i++) {
        arrayNode.add(sortingArray.get(i).get("target"));
    }
}

From source file:lumbermill.elasticsearch.ElasticSearchBulkResponseEvent.java

private static JsonNode toPostponsedEvent(JsonEvent jsonEvent) {
    ObjectNode objectNode = Json.OBJECT_MAPPER.createObjectNode();
    objectNode.putObject("create").put("_id", "ID_CREATION_POSTPONED").put("status", 202);
    return objectNode;
}

From source file:net.hamnaberg.json.Link.java

public static Link create(URI href, String rel, Optional<String> prompt, Optional<String> name,
        Optional<Render> render) {
    ObjectNode node = JsonNodeFactory.instance.objectNode();
    node.put("href", Optional.ofNullable(href)
            .orElseThrow(() -> new IllegalArgumentException("Href may not be null")).toString());
    node.put("rel", Optional.ofNullable(rel)
            .orElseThrow(() -> new IllegalArgumentException("Relation may not be null")));
    prompt.ifPresent(value -> node.put("prompt", value));
    render.ifPresent(value -> node.put("render", value.getName()));
    name.ifPresent(value -> node.put("name", value));
    return new Link(node);
}

From source file:api.Status.java

public static Result getMeta() {
    ObjectNode meta = Json.newObject();

    OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
    meta.put("osName", os.getName());
    meta.put("osVersion", os.getVersion());
    meta.put("arch", os.getArch());
    meta.put("cpus", os.getAvailableProcessors());

    return ok(meta.toString());
}