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

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

Introduction

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

Prototype

public ObjectNode(JsonNodeFactory paramJsonNodeFactory) 

Source Link

Usage

From source file:org.jetbrains.webdemo.sessions.MyHttpSession.java

private void sendFileExistenceResult() {
    try {/* www  .java2  s.  c o  m*/
        ObjectNode response = new ObjectNode(JsonNodeFactory.instance);
        if (MySqlConnector.getInstance().getFile(request.getParameter("publicId")) != null) {
            response.put("exists", true);
        } else {
            response.put("exists", false);
        }
        writeResponse(response.toString(), HttpServletResponse.SC_OK);
    } catch (NullPointerException e) {
        writeResponse("Can't get parameters", HttpServletResponse.SC_BAD_REQUEST);
    } catch (DatabaseOperationException e) {
        writeResponse(e.getMessage(), HttpServletResponse.SC_BAD_REQUEST);
    }
}

From source file:org.apache.olingo.fit.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(Constants.get(ConstantKey.JSON_ODATAMETADATA_NAME),
            Constants.get(ConstantKey.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;/*from   w w w .  jav a  2s .co m*/
        } else {
            absoluteURI = Constants.get(ConstantKey.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(), Constants.ENCODING);
}

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

/**
 * Creates a JSON object from the given Sone.
 *
 * @param sone/* www  . ja v a  2 s . co m*/
 *            The Sone to convert to a JSON object
 * @return The JSON representation of the given Sone
 */
private JsonNode createJsonSone(Sone sone) {
    ObjectNode jsonSone = new ObjectNode(instance);
    jsonSone.put("id", sone.getId());
    jsonSone.put("name", SoneAccessor.getNiceName(sone));
    jsonSone.put("local", sone.getInsertUri() != null);
    jsonSone.put("status", sone.getStatus().name());
    jsonSone.put("modified", webInterface.getCore().isModifiedSone(sone));
    jsonSone.put("locked", webInterface.getCore().isLocked(sone));
    jsonSone.put("lastUpdatedUnknown", sone.getTime() == 0);
    synchronized (dateFormat) {
        jsonSone.put("lastUpdated", dateFormat.format(new Date(sone.getTime())));
    }
    jsonSone.put("lastUpdatedText", GetTimesAjaxPage.getTime(webInterface, sone.getTime()).getText());
    return jsonSone;
}

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

public static InputStream getJsonProperty(final InputStream src, final String[] path, final String edmType)
        throws Exception {

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

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

    if (StringUtils.isNotBlank(edmType)) {
        property.put(JSON_ODATAMETADATA_NAME, ODATA_METADATA_PREFIX + edmType);
    }/*  ww w.  j  av a2s .  c om*/

    JsonNode jsonNode = getJsonProperty(srcNode, path, 0);
    if (jsonNode.isObject()) {
        property.putAll((ObjectNode) jsonNode);
    } else {
        property.put("value", jsonNode.asText());
    }

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

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

    return res;
}

From source file:io.syndesis.maven.ExtractConnectorDescriptorsMojo.java

private ObjectNode getComponentMeta(ClassLoader classLoader) {
    Properties properties = loadComponentProperties(classLoader);
    if (properties == null) {
        return null;
    }//from   ww w  . j a va  2s . c  o  m
    String components = (String) properties.get("components");
    if (components == null) {
        return null;
    }
    String[] part = components.split("\\s");
    ObjectNode componentMeta = new ObjectNode(JsonNodeFactory.instance);
    for (String scheme : part) {
        // find the class name
        String javaType = extractComponentJavaType(classLoader, scheme);
        if (javaType == null) {
            continue;
        }
        String schemeMeta = loadComponentJSonSchema(classLoader, scheme, javaType);
        if (schemeMeta == null) {
            continue;
        }
        componentMeta.set(scheme, new TextNode(schemeMeta));
    }
    return componentMeta.size() > 0 ? componentMeta : null;
}

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

private void processMetricReport(final MetricReport report) {
    final Map<String, Set<String>> metrics = _subscriptions.get(report.getService());
    if (metrics == null) {
        LOGGER.trace().setMessage("Not sending MetricReport")
                .addData("reason", "service not found in subscriptions").addData("service", report.getService())
                .log();// w w  w .j a  v a2s.  c  o m
        return;
    }
    final Set<String> stats = metrics.get(report.getMetric());
    if (stats == null) {
        LOGGER.trace().setMessage("Not sending MetricReport")
                .addData("reason", "metric not found in subscriptions").addData("metric", report.getMetric())
                .log();
        return;
    }
    if (!stats.contains(report.getStatistic())) {
        LOGGER.trace().setMessage("Not sending MetricReport")
                .addData("reason", "statistic not found in subscriptions")
                .addData("statistic", report.getStatistic()).log();
        return;
    }

    //TODO(barp): Map with a POJO mapper [MAI-184]
    final ObjectNode event = new ObjectNode(OBJECT_MAPPER.getNodeFactory());
    event.put("server", report.getHost());
    event.put("service", report.getService());
    event.put("metric", report.getMetric());
    event.put("timestamp", report.getPeriodStart().getMillis());
    event.put("statistic", report.getStatistic());
    event.put("data", report.getValue());

    _connection.sendCommand(COMMAND_REPORT_METRIC, event);
}

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

private void processMetricReport(final MetricReport report) {
    final Map<String, Set<String>> metrics = _subscriptions.get(report.getService());
    if (metrics == null) {
        LOGGER.trace().setMessage("Not sending MetricReport")
                .addData("reason", "service not found in subscriptions").addData("service", report.getService())
                .log();//  w  w  w. j a v a2 s.co  m
        return;
    }
    final Set<String> stats = metrics.get(report.getMetric());
    if (stats == null) {
        LOGGER.trace().setMessage("Not sending MetricReport")
                .addData("reason", "metric not found in subscriptions").addData("metric", report.getMetric())
                .log();
        return;
    }
    if (!stats.contains(report.getStatistic())) {
        LOGGER.trace().setMessage("Not sending MetricReport")
                .addData("reason", "statistic not found in subscriptions")
                .addData("statistic", report.getStatistic()).log();
        return;
    }

    //TODO(barp): Map with a POJO mapper [MAI-184]
    final ObjectNode event = new ObjectNode(OBJECT_MAPPER.getNodeFactory());
    event.put("server", report.getHost());
    event.put("service", report.getService());
    event.put("metric", report.getMetric());
    event.put("timestamp", report.getPeriodStart().getMillis());
    event.put("statistic", report.getStatistic());
    event.put("data", report.getValue());
    _connection.sendCommand(COMMAND_REPORT_METRIC, event);
}

From source file:com.redhat.lightblue.metadata.parser.JSONMetadataParserTest.java

License:asdf

@Test
public void getStringProperty() {
    String name = "name";
    String value = "value";
    ObjectNode parent = new ObjectNode(factory);
    parent.put(name, value);//from   w  w w. j a v a2s  .  co  m

    Assert.assertEquals(value, parser.getStringProperty(parent, name));
}

From source file:com.redhat.lightblue.crud.rdbms.RDBMSProcessor.java

public static void convertProjection(RDBMSContext rdbmsContext, List<InOut> inout, DynVar dynVar) {
    List<JsonDoc> l = new ArrayList<>();
    JsonDoc jd = new JsonDoc(new ObjectNode(rdbmsContext.getJsonNodeFactory()));
    l.add(jd);//from w  w  w .j  ava2 s .  c om

    for (String key : dynVar.getKeys()) {
        List values = dynVar.getValues(key);
        convertRecursion(rdbmsContext, jd, key, values, null);
    }

    rdbmsContext.getCrudOperationContext().addDocuments(l);
}

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  a  v a 2 s. c o m

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

    return Action.CANCELLED;
}