Package com.fasterxml.jackson.databind

Examples of com.fasterxml.jackson.databind.ObjectWriter.writeValueAsString()


    multiViewBean.setAge(16);
    multiViewBean.setOtherValue("others");

    // public view
    ObjectWriter publicWriter = mapper.getMapper().writerWithView(Views.Public.class);
    assertThat(publicWriter.writeValueAsString(multiViewBean)).isEqualTo(
        "{\"name\":\"Foo\",\"otherValue\":\"others\"}");

    // internal view
    ObjectWriter internalWriter = mapper.getMapper().writerWithView(Views.Internal.class);
    assertThat(internalWriter.writeValueAsString(multiViewBean))
View Full Code Here


    assertThat(publicWriter.writeValueAsString(multiViewBean)).isEqualTo(
        "{\"name\":\"Foo\",\"otherValue\":\"others\"}");

    // internal view
    ObjectWriter internalWriter = mapper.getMapper().writerWithView(Views.Internal.class);
    assertThat(internalWriter.writeValueAsString(multiViewBean))
        .isEqualTo("{\"age\":16,\"otherValue\":\"others\"}");

  }

  public static class Views {
View Full Code Here

    {
      try
      {
        request.addHeader("Content-type", "application/json");
        ObjectWriter writer = mapper.writer();
        String payload = writer.writeValueAsString(obj);
        StringEntity entity = new StringEntity(payload);
        log.debug("Payload:\n " + payload);
        request.setEntity(entity);
      } catch (JsonMappingException e)
      {
View Full Code Here

    {
      try
      {
        request.addHeader("Content-type", "application/json");
        ObjectWriter writer = mapper.writer();
        String payload = writer.writeValueAsString(obj);
        StringEntity entity = new StringEntity(payload);
        log.debug("Payload:\n " + payload);
        request.setEntity(entity);
      } catch (JsonMappingException e)
      {
View Full Code Here

        try {
      Boolean debug = Boolean.valueOf(AdaptrexServices.getConfig().get(AdaptrexConfig.DEBUG));
      ObjectMapper mapper = new ObjectMapper();
            if (debug) {
                ObjectWriter writer = mapper.writerWithDefaultPrettyPrinter();
                return writer.writeValueAsString(object);
            } else {
                return mapper.writeValueAsString(object);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
View Full Code Here

            if (request instanceof HttpPost) {
                String requestPayload = CharStreams.toString(new InputStreamReader(((HttpPost) request)
                        .getEntity()
                        .getContent()));
                JsonNode requestNode = jsonMapper.readTree(requestPayload);
                System.out.println(writer.writeValueAsString(requestNode));
            } else {
                System.out.println("(No body)");
            }

            System.out.println("=== RESPONSE ===");
View Full Code Here

                response.setEntity(entity);
                String responsePayload = CharStreams.toString(new InputStreamReader(entity.getContent()));

                try {
                    JsonNode responseNode = jsonMapper.readTree(responsePayload);
                    System.out.println(writer.writeValueAsString(responseNode));
                } catch (JsonProcessingException e) {
                    System.out.println(responsePayload);
                }
            } else {
                System.out.println("(No body)");
View Full Code Here

            }
            text = VelocityEngineUtils.mergeTemplateIntoString(
                    velocityEngine, CODE_TEMPLATES  + embeddedType.toString().toLowerCase() +"_code.vm", "utf-8", model);
            String string = new String(text.getBytes("UTF-8"));
            embebedBody.setBody(string);
            final String json = ow.writeValueAsString(embebedBody);
            out.print(callback + "(" + json + ")");
        } catch (Exception e) {
            e.printStackTrace();
            out.print(callback + "(" + Boolean.FALSE + ")");
        }
View Full Code Here

                text = VelocityEngineUtils.mergeTemplateIntoString(
                        velocityEngine, HTML_TEMPLATES + "/profile.vm", "utf-8", model);
            }
            final String string = new String(text.getBytes("UTF-8"));
            embebedBody.setBody(string);
            final String json = ow.writeValueAsString(embebedBody);
            out.print(callback + "(" + json + ")");
        } catch (Exception e) {
            e.printStackTrace();
            out.print(callback + "(" + Boolean.FALSE + ")");
        }
View Full Code Here

    public String getSchemaForClass(Class<?> clazz) {
        LOG.info("Looking up schema for " + clazz.getCanonicalName());
        String name = clazz.getName();
        try {
            ObjectWriter writer = mapper.writer().with(new FourSpacePrettyPrinter());
            return writer.writeValueAsString(mapper.generateJsonSchema(clazz));
        } catch (Exception e) {
            LOG.log(Level.FINEST, "Failed to generate JSON schema for class " + name, e);
            return "";
        }
    }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.