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:com.enitalk.controllers.youtube.BotAware.java

public void sendTag(ObjectNode dest) throws IOException, ExecutionException {
    String auth = botAuth();/*from   w w  w .  java  2  s  .c o  m*/
    String tagResponse = Request.Post(env.getProperty("bot.sendTag"))
            .addHeader("Authorization", "Bearer " + auth)
            .bodyString(dest.toString(), ContentType.APPLICATION_JSON).socketTimeout(20000).connectTimeout(5000)
            .execute().returnContent().asString();

    logger.info("Tag command sent to a bot {}, response {}", dest, tagResponse);
}

From source file:com.redhat.lightblue.metadata.types.BinaryTypeTest.java

License:asdf

@Test
public void testEmbeddedPDF() throws FileNotFoundException, IOException, JSONException {
    String pdfFilename = "./BinaryTypeTest-sample.pdf";

    InputStream is = this.getClass().getClassLoader().getResourceAsStream(pdfFilename);

    ByteArrayOutputStream buffer = new ByteArrayOutputStream();

    int read;//from w w  w .j  ava2 s .  c o  m
    byte[] bytes = new byte[1000];

    while ((read = is.read(bytes, 0, bytes.length)) != -1) {
        buffer.write(bytes, 0, read);
    }

    String encoded = DatatypeConverter.printBase64Binary(buffer.toByteArray());

    String jsonString = "{\"binaryData\": \"" + encoded + "\"}";

    JsonNode nodeIn = JsonUtils.json(jsonString);
    JsonNode binaryDataNodeIn = nodeIn.get("binaryData");

    byte[] bytesOut = binaryDataNodeIn.binaryValue();

    JsonNodeFactory jsonNodeFactory = new JsonNodeFactory(true);
    JsonNode binaryDataNodeOut = binaryType.toJson(jsonNodeFactory, bytesOut);

    ObjectNode nodeOut = jsonNodeFactory.objectNode();
    nodeOut.set("binaryData", binaryDataNodeOut);

    JSONAssert.assertEquals(jsonString, nodeOut.toString(), JSONCompareMode.LENIENT);
}

From source file:com.smallpay.workflow.service.api.model.ModelSaveRestResource.java

@RequestMapping(value = "/service/model/{modelId}/save", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
@ResponseStatus(value = HttpStatus.OK)/*w  w w .jav  a  2  s.co m*/
public void saveModel(@PathVariable String modelId, @RequestParam MultiValueMap<String, String> values) {
    try {

        Model model = repositoryService.getModel(modelId);

        ObjectNode modelJson = (ObjectNode) objectMapper.readTree(model.getMetaInfo());

        modelJson.put(MODEL_NAME, values.getFirst("name"));
        modelJson.put(MODEL_DESCRIPTION, values.getFirst("description"));
        model.setMetaInfo(modelJson.toString());
        model.setName(values.getFirst("name"));

        repositoryService.saveModel(model);

        repositoryService.addModelEditorSource(model.getId(), values.getFirst("json_xml").getBytes("utf-8"));

        InputStream svgStream = new ByteArrayInputStream(values.getFirst("svg_xml").getBytes("utf-8"));
        TranscoderInput input = new TranscoderInput(svgStream);

        PNGTranscoder transcoder = new PNGTranscoder();
        // Setup output
        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
        TranscoderOutput output = new TranscoderOutput(outStream);

        // Do the transformation
        transcoder.transcode(input, output);
        final byte[] result = outStream.toByteArray();
        repositoryService.addModelEditorSourceExtra(model.getId(), result);
        outStream.close();

    } catch (Exception e) {
        LOGGER.error("Error saving model", e);
        throw new ActivitiException("Error saving model", e);
    }
}

From source file:com.enitalk.controllers.youtube.BotAware.java

public JsonNode getBotCommandsByTag(JsonNode dest, String tag) throws IOException, ExecutionException {
    String auth = botAuth();//w ww. jav  a  2  s. c o  m
    ObjectNode j = jackson.createObjectNode();
    j.set("dest", dest);
    j.put("tag", tag);

    String tagResponse = Request.Post(env.getProperty("bot.commands.by.tag"))
            .addHeader("Authorization", "Bearer " + auth).bodyString(j.toString(), ContentType.APPLICATION_JSON)
            .socketTimeout(20000).connectTimeout(5000).execute().returnContent().asString();

    logger.info("Command by tag find response {}", tagResponse);
    return jackson.readTree(tagResponse);
}

From source file:com.indeed.imhotep.web.QueryMetadata.java

public String toJSON() {
    final ObjectMapper mapper = new ObjectMapper();
    final ObjectNode headerObject = mapper.createObjectNode();
    for (QueryMetadataItem queryMetadataItem : items) {
        headerObject.put(queryMetadataItem.name, queryMetadataItem.value);
    }/*from   www .j a v a 2s.  co  m*/
    return headerObject.toString();
}

From source file:org.pf9.pangu.app.act.rest.editor.model.ModelSaveRestResource.java

@RequiresPermissions("act:model:edit")
@RequestMapping(value = "/act/service/model/{modelId}/save", method = RequestMethod.PUT)
@ResponseStatus(value = HttpStatus.OK)/*from  ww w.j a va 2s . c  om*/
public void saveModel(@PathVariable String modelId, @RequestBody MultiValueMap<String, String> values) {
    try {

        Model model = repositoryService.getModel(modelId);

        ObjectNode modelJson = (ObjectNode) objectMapper.readTree(model.getMetaInfo());

        modelJson.put(MODEL_NAME, values.getFirst("name"));
        modelJson.put(MODEL_DESCRIPTION, values.getFirst("description"));
        model.setMetaInfo(modelJson.toString());
        model.setName(values.getFirst("name"));

        repositoryService.saveModel(model);

        repositoryService.addModelEditorSource(model.getId(), values.getFirst("json_xml").getBytes("utf-8"));

        InputStream svgStream = new ByteArrayInputStream(values.getFirst("svg_xml").getBytes("utf-8"));
        TranscoderInput input = new TranscoderInput(svgStream);

        PNGTranscoder transcoder = new PNGTranscoder();
        // Setup output
        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
        TranscoderOutput output = new TranscoderOutput(outStream);

        // Do the transformation
        transcoder.transcode(input, output);
        final byte[] result = outStream.toByteArray();
        repositoryService.addModelEditorSourceExtra(model.getId(), result);
        outStream.close();

    } catch (Exception e) {
        LOGGER.error("Error saving model", e);
        throw new ActivitiException("Error saving model", e);
    }
}

From source file:org.activiti.service.engine.FormInstanceService.java

public JsonNode getFormInstances(ServerConfig serverConfig, ObjectNode objectNode) {

    JsonNode resultNode = null;//from   www.  j a v  a 2 s  .co m

    try {
        URIBuilder builder = clientUtil.createUriBuilder("/query/form-instances");
        HttpPost post = clientUtil.createPost(builder.toString(), serverConfig);
        post.setEntity(clientUtil.createStringEntity(objectNode.toString()));

        resultNode = clientUtil.executeRequest(post, serverConfig);
    } catch (Exception ex) {
        throw new ActivitiServiceException(ex.getMessage(), ex);
    }

    return resultNode;
}

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

private String prepareAppBrokerJsonRequest(String serviceName, String serviceDescription) {
    String planId = UUID.randomUUID().toString();
    String serviceId = UUID.randomUUID().toString();

    ObjectMapper mapper = new ObjectMapper();

    ArrayNode plansArray = mapper.createArrayNode();
    ObjectNode planNode = mapper.createObjectNode();
    planNode.put("id", planId);
    plansArray.add(planNode);/*w w  w. ja v a2s  . co m*/

    ObjectNode guidNode = mapper.createObjectNode();
    guidNode.put("guid", appGuid);

    ObjectNode metadataNode = mapper.createObjectNode();
    metadataNode.set("metadata", guidNode);

    ObjectNode json = mapper.createObjectNode();
    json.set("app", metadataNode);
    json.put("id", serviceId);
    json.set("plans", plansArray);
    json.put("description", serviceDescription);
    json.put("name", serviceName);

    return json.toString();
}

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

public String toString() {
    ObjectNode objectNode = mapper.createObjectNode();
    if (!filtersMap.keySet().isEmpty()) {
        for (Map.Entry<String, String> s : filtersMap.entrySet()) {
            objectNode.putObject(s.getKey()).put(s.getValue(), true);
        }// w w  w.  j a  v a2s.c om
    }

    return objectNode.toString();
}

From source file:org.ow2.chameleon.everest.impl.TestParameterToBeanSupport.java

@Test
public void testBeaninifcation() {
    ObjectNode node = objectMapper.createObjectNode().put("message", "a message").put("count", 1);
    node.putArray("names").add("a").add("b").add("c");

    DefaultRequest request = new DefaultRequest(Action.READ, Path.from("/foo"),
            new ImmutableMap.Builder<String, String>().put("test", node.toString()).build());

    MyBean bean = request.get("test", MyBean.class);
    assertThat(bean.getCount()).isEqualTo(1);
    assertThat(bean.getMessage()).isEqualTo("a message");
    assertThat(bean.getNames()).contains("a").contains("b").contains("c");
}