Example usage for com.fasterxml.jackson.databind.node JsonNodeFactory instance

List of usage examples for com.fasterxml.jackson.databind.node JsonNodeFactory instance

Introduction

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

Prototype

JsonNodeFactory instance

To view the source code for com.fasterxml.jackson.databind.node JsonNodeFactory instance.

Click Source Link

Usage

From source file:org.atmosphere.sockjs.SockJsAtmosphereInterceptor.java

protected Action info(AtmosphereResource r) {
    final AtmosphereResponse response = r.getResponse();
    final AtmosphereRequest request = r.getRequest();

    response.headers().put("Content-Type", "application/json; charset=UTF-8");
    ObjectNode json = new ObjectNode(JsonNodeFactory.instance);
    json.put("websocket", supportWebSocket);
    json.putArray("origins").add("*:*");
    json.put("entropy", new Random().nextInt());
    r.write(JsonCodec.encode(json));/*from w  w w  .j ava 2s .c  om*/

    if (baseURL.get().isEmpty()) {
        baseURL.set(request.getRequestURI().substring(0, request.getRequestURI().indexOf("/info")));
    }

    return Action.CANCELLED;
}

From source file:com.arpnetworking.metrics.proxy.models.protocol.v1.MetricMessagesProcessor.java

private void processMetricsList(final MetricsList metricsList) {
    //TODO(barp): Map with a POJO mapper [MAI-184]
    final ObjectNode dataNode = JsonNodeFactory.instance.objectNode();
    final ArrayNode services = JsonNodeFactory.instance.arrayNode();
    for (final Map.Entry<String, Map<String, Set<String>>> service : metricsList.getMetrics().entrySet()) {
        final ObjectNode serviceObject = JsonNodeFactory.instance.objectNode();
        serviceObject.put("name", service.getKey());
        final ArrayNode metrics = JsonNodeFactory.instance.arrayNode();
        for (final Map.Entry<String, Set<String>> metric : service.getValue().entrySet()) {
            final ObjectNode metricObject = JsonNodeFactory.instance.objectNode();
            metricObject.put("name", metric.getKey());
            final ArrayNode stats = JsonNodeFactory.instance.arrayNode();
            for (final String statistic : metric.getValue()) {
                final ObjectNode statsObject = JsonNodeFactory.instance.objectNode();
                statsObject.put("name", statistic);
                statsObject.set("children", JsonNodeFactory.instance.arrayNode());
                stats.add(statsObject);//  w w w.ja  v a 2s . c  om
            }
            metricObject.set("children", stats);
            metrics.add(metricObject);
        }
        serviceObject.set("children", metrics);
        services.add(serviceObject);
    }
    dataNode.set("metrics", services);

    _connection.sendCommand(COMMAND_METRICS_LIST, dataNode);
}

From source file:org.apache.olingo.fit.utils.AbstractJSONUtilities.java

@Override
public InputStream getProperty(final String entitySetName, final String entityId, final List<String> path,
        final String edmType) throws Exception {

    final InputStream src = fsManager.readFile(Commons.getEntityBasePath(entitySetName, entityId) + ENTITY,
            Accept.JSON_FULLMETA);/*from  w  w w.ja  va  2 s.c  o  m*/

    final ObjectMapper mapper = new ObjectMapper();
    final JsonNode srcNode = mapper.readTree(src);

    final ObjectNode propertyNode = new ObjectNode(JsonNodeFactory.instance);

    if (StringUtils.isNotBlank(edmType)) {
        propertyNode.put(JSON_ODATAMETADATA_NAME, ODATA_METADATA_PREFIX + edmType);
    }

    JsonNode jsonNode = getProperty(srcNode, path);

    if (jsonNode.isArray()) {
        propertyNode.put("value", (ArrayNode) jsonNode);
    } else if (jsonNode.isObject()) {
        propertyNode.putAll((ObjectNode) jsonNode);
    } else {
        propertyNode.put("value", jsonNode.asText());
    }

    final ByteArrayOutputStream bos = new ByteArrayOutputStream();
    mapper.writeValue(bos, propertyNode);

    final InputStream res = new ByteArrayInputStream(bos.toByteArray());
    IOUtils.closeQuietly(bos);

    return res;
}

From source file:org.kitesdk.apps.streaming.StreamDescription.java

private TreeNode toJson() {

    JsonNodeFactory js = JsonNodeFactory.instance;

    ObjectNode root = js.objectNode();// w ww  .  j ava2 s.  c  om

    root.put(NAME, getJobName());
    root.put(JOBCLASS, getJobClass().getName());

    ArrayNode streamsArray = js.arrayNode();

    for (Stream stream : getStreams().values()) {

        ObjectNode streamNode = streamsArray.addObject();

        streamNode.put(NAME, stream.getName());

        ObjectNode properties = js.objectNode();

        for (Map.Entry<String, String> prop : stream.getProperties().entrySet()) {

            properties.put(prop.getKey(), prop.getValue());
        }

        streamNode.put(PROPS, properties);
    }

    root.put(STREAMS, streamsArray);

    ArrayNode viewsArray = js.arrayNode();

    for (Map.Entry<String, URI> view : getViewUris().entrySet()) {

        ObjectNode viewNode = viewsArray.addObject();

        viewNode.put(NAME, view.getKey());
        viewNode.put(URI_PROP, view.getValue().toString());
    }

    root.put(VIEWS, viewsArray);

    return root;
}

From source file:io.gs2.ranking.Gs2RankingClient.java

/**
 * ????<br>/*from   w ww . j ava  2s . c  om*/
 * <br>
 *
 * @param request 
        
 * @return ?
        
 */

public UpdateGameModeResult updateGameMode(UpdateGameModeRequest request) {

    ObjectNode body = JsonNodeFactory.instance.objectNode().put("calcInterval", request.getCalcInterval());
    if (request.getPutScoreTriggerScript() != null)
        body.put("putScoreTriggerScript", request.getPutScoreTriggerScript());
    if (request.getPutScoreDoneTriggerScript() != null)
        body.put("putScoreDoneTriggerScript", request.getPutScoreDoneTriggerScript());
    if (request.getCalculateRankingDoneTriggerScript() != null)
        body.put("calculateRankingDoneTriggerScript", request.getCalculateRankingDoneTriggerScript());
    HttpPut put = createHttpPut(Gs2Constant.ENDPOINT_HOST + "/ranking/"
            + (request.getRankingTableName() == null || request.getRankingTableName().equals("") ? "null"
                    : request.getRankingTableName())
            + "/mode/"
            + (request.getGameMode() == null || request.getGameMode().equals("") ? "null"
                    : request.getGameMode())
            + "", credential, ENDPOINT, UpdateGameModeRequest.Constant.MODULE,
            UpdateGameModeRequest.Constant.FUNCTION, body.toString());
    if (request.getRequestId() != null) {
        put.setHeader("X-GS2-REQUEST-ID", request.getRequestId());
    }

    return doRequest(put, UpdateGameModeResult.class);

}

From source file:org.obiba.mica.micaConfig.service.MicaConfigService.java

private JsonNode addTaxonomy(TaxonomyTarget taxonomyTarget, String taxonomyKey, JsonNode original,
        String locale) {//from w w w.j a  va  2s . c  o  m

    JsonNode taxonomyNode = getTaxonomyNode(taxonomyTarget, locale);

    ObjectNode containerNode = new ObjectNode(JsonNodeFactory.instance);
    containerNode.set(taxonomyKey, taxonomyNode);

    return mergeJson(original, containerNode);
}

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));/*from  w ww  .j  av  a  2s . c om*/
    }
    return node;
}

From source file:org.eel.kitchen.jsonschema.report.ValidationReport.java

/**
 * Return the list of validation messages as a JSON array
 *
 * <p>This method makes its best to order validation messages correctly.</p>
 *
 * <p>Each message in the resulting array is a JSON object, with the
 * contents of the {@link Message} and with an added member named {@code
 * path}, which contains the path into the instance where the error has
 * occurred (as a {@link JsonPointer}).</p>
 *
 * @see Message#toJsonNode()//w  ww  .  j  ava  2  s. co  m
 *
 * @return a JSON array with all validation messages
 */
public JsonNode asJsonArray() {
    final ArrayNode ret = JsonNodeFactory.instance.arrayNode();
    ObjectNode node;

    final Iterable<JsonPointer> paths = Ordering.natural().sortedCopy(msgMap.keySet());

    List<Message> messages;

    for (final JsonPointer ptr : paths) {
        messages = MESSAGE_ORDER.sortedCopy(msgMap.get(ptr));
        for (final Message msg : messages) {
            node = JsonNodeFactory.instance.objectNode().put("path", ptr.toString());
            // I hate to do that...
            node.putAll((ObjectNode) msg.toJsonNode());
            ret.add(node);
        }
    }

    return ret;
}

From source file:io.gs2.timer.Gs2TimerClient.java

/**
 * ?????<br>/*from  w ww .  j  a  v a  2  s.c  o m*/
 * <br>
 * ? timestamp ???????????<br>
 * ????1??URL?????<br>
 * <br>
 * ?????????????<br>
 * <br>
 * ????????<br>
 * ??????????????????????????<br>
 * <br>
 * ??????????????????????<br>
 * <br>
 *
 * @param request 
        
 * @return ?
        
 */

public CreateTimerResult createTimer(CreateTimerRequest request) {

    ObjectNode body = JsonNodeFactory.instance.objectNode().put("callbackMethod", request.getCallbackMethod())
            .put("callbackUrl", request.getCallbackUrl()).put("executeTime", request.getExecuteTime());
    if (request.getCallbackBody() != null)
        body.put("callbackBody", request.getCallbackBody());
    if (request.getRetryMax() != null)
        body.put("retryMax", request.getRetryMax());

    HttpPost post = createHttpPost(
            Gs2Constant.ENDPOINT_HOST + "/timerPool/"
                    + (request.getTimerPoolName() == null || request.getTimerPoolName().equals("") ? "null"
                            : request.getTimerPoolName())
                    + "/timer",
            credential, ENDPOINT, CreateTimerRequest.Constant.MODULE, CreateTimerRequest.Constant.FUNCTION,
            body.toString());
    if (request.getRequestId() != null) {
        post.setHeader("X-GS2-REQUEST-ID", request.getRequestId());
    }

    return doRequest(post, CreateTimerResult.class);

}

From source file:org.obiba.mica.micaConfig.service.MicaConfigService.java

private JsonNode getTaxonomyNode(TaxonomyTarget taxonomyTarget, String locale) {

    Taxonomy taxonomy = taxonomyConfigService.findByTarget(taxonomyTarget);

    ObjectNode vocabularies = new ObjectNode(JsonNodeFactory.instance);
    for (Vocabulary vocabulary : taxonomy.getVocabularies()) {
        ObjectNode vocabularyNode = createObjectNode(vocabulary, locale);
        vocabularyNode = addTerms(vocabularyNode, vocabulary.getTerms(), locale);
        vocabularies.set(vocabulary.getName(), vocabularyNode);
    }/*from ww  w . jav  a 2s .c om*/

    ObjectNode taxonomyNode = createObjectNode(taxonomy, locale);
    taxonomyNode.set("vocabulary", vocabularies);

    return taxonomyNode;
}