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

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

Introduction

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

Prototype

public String toString() 

Source Link

Usage

From source file:dk.dbc.rawrepo.oai.ResumptionTokenTest.java

@Test
public void testResumptionTokenVerbatim() throws Exception {
    ObjectNode json = (ObjectNode) new ObjectMapper().readTree("{\"foo\":\"bar\"}");
    assertEquals("{\"foo\":\"bar\"}", json.toString());
}

From source file:org.envirocar.aggregation.AggregatedTracksServlet.java

private String createAggregatedTracksList() throws SQLException {
    ResultSet rs = this.connection.executeQueryStatement(query);

    ArrayNode array = om.createArrayNode();
    ObjectNode object;//from  w  ww .ja v  a 2  s.  co  m
    String id;
    Timestamp ts;
    while (rs.next()) {
        object = om.createObjectNode();
        id = rs.getString("id");
        ts = rs.getTimestamp(AGGREGATION_DATE);

        object.put(id, df.format(new Date(ts.getTime())));

        array.add(object);
    }

    rs.close();

    ObjectNode node = om.createObjectNode();

    node.put("tracks", array);
    return node.toString();
}

From source file:org.onosproject.segmentrouting.web.TunnelWebResource.java

/**
 * Get all segment routing tunnels./*from  w w w  .  j a  v a  2 s.co m*/
 * Returns an array of segment routing tunnels.
 *
 * @return status of OK
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getTunnel() {
    SegmentRoutingService srService = get(SegmentRoutingService.class);
    List<Tunnel> tunnels = srService.getTunnels();
    ObjectNode result = new ObjectMapper().createObjectNode();
    result.set("tunnel", new TunnelCodec().encode(tunnels, this));

    return ok(result.toString()).build();
}

From source file:io.liveoak.security.policy.drools.integration.DroolsPolicyConfigResource.java

@Override
public void properties(ResourceState props) throws Exception {
    // Keep just "rules" . Other props not important for us
    Set<String> namesCopy = new HashSet<>(props.getPropertyNames());
    for (String propName : namesCopy) {
        if (!RULES_PROPERTY.equals(propName)) {
            props.removeProperty(propName);
        }//from  w  ww  . j av a  2s.c  o m
    }

    ObjectNode objectNode = ConversionUtils.convert(props);
    ObjectMapper om = ObjectMapperFactory.create();
    this.droolsPolicyConfig = om.readValue(objectNode.toString(), DroolsPolicyConfig.class);

    new DroolsPolicyConfigurator().configure(this.droolsPolicy, this.droolsPolicyConfig);
}

From source file:com.baasbox.controllers.ScriptInvoker.java

public static JsonNode serializeRequest(String path, Http.Request request) {
    Http.RequestBody body = request.body();

    Map<String, String[]> headers = request.headers();
    String method = request.method();
    Map<String, String[]> query = request.queryString();
    path = path == null ? "/" : path;
    ObjectNode reqJson = Json.mapper().createObjectNode();
    reqJson.put("method", method);
    reqJson.put("path", path);
    reqJson.put("remote", request.remoteAddress());

    if (!StringUtils.containsIgnoreCase(request.getHeader(CONTENT_TYPE), "application/json")) {
        String textBody = body == null ? null : body.asText();
        if (textBody == null) {
            //fixes issue 627
            Map<String, String> params = BodyHelper.requestData(request);
            JsonNode jsonBody = Json.mapper().valueToTree(params);
            reqJson.put("body", jsonBody);
        } else {/* w  w w .  j a va 2s  .c o m*/
            reqJson.put("body", textBody);
        }
    } else {
        reqJson.put("body", body.asJson());
    }

    JsonNode queryJson = Json.mapper().valueToTree(query);
    reqJson.put("queryString", queryJson);
    JsonNode headersJson = Json.mapper().valueToTree(headers);
    reqJson.put("headers", headersJson);
    BaasBoxLogger.debug("Serialized request to pass to the script: ");
    BaasBoxLogger.debug(reqJson.toString());
    return reqJson;
}

From source file:org.trustedanalytics.h2oscoringengine.publisher.steps.CreatingPlanVisibilityStep.java

private String prepareServiceVisibilityJsonRequest(String servicePlanGuid, String orgGuid) {

    ObjectMapper mapper = new ObjectMapper();

    ObjectNode json = mapper.createObjectNode();
    json.put("service_plan_guid", servicePlanGuid);
    json.put("organization_guid", orgGuid);

    return json.toString();
}

From source file:org.onosproject.segmentrouting.web.PolicyWebResource.java

/**
 * Get all segment routing policies.//from   ww w . j a  va2 s  . c o  m
 * Returns an array of segment routing policies.
 *
 * @return status of OK
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getPolicy() {
    SegmentRoutingService srService = get(SegmentRoutingService.class);
    List<Policy> policies = srService.getPolicies();
    ObjectNode result = new ObjectMapper().createObjectNode();
    result.set("policy", new PolicyCodec().encode(policies, this));

    return ok(result.toString()).build();
}

From source file:org.onlab.stc.MonitorWebSocket.java

public synchronized void sendMessage(ObjectNode message) {
    try {/*from w  w  w.jav  a  2 s  .  co m*/
        if (connection.isOpen()) {
            connection.sendMessage(message.toString());
        }
    } catch (IOException e) {
        print("Unable to send message %s to GUI due to %s", message, e);
    }
}

From source file:org.obiba.mica.micaConfig.rest.CustomTranslationsResource.java

@GET
@Timed//from  w  ww  . ja  v  a 2 s.  com
@Path("/export")
@Produces("application/json")
public Response exportTranslation() {
    List<String> locales = micaConfigService.getConfig().getLocalesAsString();
    ObjectNode node = objectMapper.createObjectNode();
    locales.forEach(l -> node.set(l, getTranslations(l)));

    return Response.ok(node.toString()).build();
}

From source file:azkaban.crypto.CryptoV1.java

@Override
public String encrypt(String plaintext, String passphrase, Version cryptoVersion) {
    Preconditions.checkArgument(Version.V1_0.equals(cryptoVersion));

    String cipheredText = newEncryptor(passphrase).encrypt(plaintext);
    ObjectNode node = MAPPER.createObjectNode();
    node.put(CIPHERED_TEXT_KEY, cipheredText);
    node.put(ICrypto.VERSION_IDENTIFIER, Version.V1_0.versionStr());

    return Crypto.encode(node.toString());
}