Package com.fasterxml.jackson.core

Examples of com.fasterxml.jackson.core.JsonGenerator.useDefaultPrettyPrinter()


        StringWriter writer = new StringWriter();
        JsonFactory factory = new JsonFactory(new ObjectMapper());
        final JsonGenerator json = factory.createGenerator(writer);
        if (pretty) {
            json.useDefaultPrettyPrinter();
        }
        json.writeStartObject();
        {
            if (("jvm".equals(classPrefix) || Strings.isNullOrEmpty(classPrefix))) {
                writeVmMetrics(json);
View Full Code Here


  }

  public MetricToJsonVisitor(Writer writer) throws IOException {
    JsonFactory jsonFactory = buildJsonFactory();
    JsonGenerator jsonGenerator = jsonFactory.createJsonGenerator(writer);
    jsonGenerator.useDefaultPrettyPrinter();
    this.jsonGenerator = jsonGenerator;
  }

  private JsonFactory buildJsonFactory() {
    return new JsonFactory();
View Full Code Here

        this.objectMapper.getJsonFactory().createJsonGenerator(outputMessage.getBody(), encoding);

    // A workaround for JsonGenerators not applying serialization features
    // https://github.com/FasterXML/jackson-databind/issues/12
    if (this.objectMapper.isEnabled(SerializationFeature.INDENT_OUTPUT)) {
      jsonGenerator.useDefaultPrettyPrinter();
    }

    try {
      if (this.prefixJson) {
        jsonGenerator.writeRaw("{} && ");
View Full Code Here

    JsonGenerator generator = this.objectMapper.getJsonFactory().createJsonGenerator(stream, this.encoding);

    // A workaround for JsonGenerators not applying serialization features
    // https://github.com/FasterXML/jackson-databind/issues/12
    if (this.objectMapper.isEnabled(SerializationFeature.INDENT_OUTPUT)) {
      generator.useDefaultPrettyPrinter();
    }

    if (this.prefixJson) {
      generator.writeRaw("{} && ");
    }
View Full Code Here

    public static final JsonFactory JSON_FACTORY = new JsonFactory();

    public static String domToJson(Node in) throws IOException {
        final StringWriter sw = new StringWriter(512);
        final JsonGenerator gen = JSON_FACTORY.createGenerator(sw);
        gen.useDefaultPrettyPrinter();
        gen.writeStartObject();
        domToJson(in, gen);
        gen.writeEndObject();
        gen.flush();
        sw.flush();
View Full Code Here

    public final void writeToStream(T value, OutputStream out, boolean indent)
        throws IOException
    {
        JsonGenerator g = JsonReader.jsonFactory.createGenerator(out);
        if (indent) {
            g = g.useDefaultPrettyPrinter();
        }
        try {
            write(value, g);
        }
        finally {
View Full Code Here

    public static final JsonFactory JSON_FACTORY = new JsonFactory();

    public static String domToJson(Node in) throws IOException {
        final StringWriter sw = new StringWriter(512);
        final JsonGenerator gen = JSON_FACTORY.createGenerator(sw);
        gen.useDefaultPrettyPrinter();
        gen.writeStartObject();
        domToJson(in, gen);
        gen.writeEndObject();
        gen.flush();
        sw.flush();
View Full Code Here

  private final JsonFactory factory = new JsonFactory();
  private final JsonGenerator gen;

  public JsonWriter(OutputStream out, boolean pretty) throws IOException{
    JsonGenerator writer = factory.createJsonGenerator(out);
    gen = pretty ? writer.useDefaultPrettyPrinter() : writer;
  }

  public void write(FieldReader reader) throws JsonGenerationException, IOException{
    writeValue(reader);
    gen.flush();
View Full Code Here

    public final void writeToStream(T value, OutputStream out, boolean indent)
        throws IOException
    {
        JsonGenerator g = JsonReader.jsonFactory.createGenerator(out);
        if (indent) {
            g = g.useDefaultPrettyPrinter();
        }
        try {
            write(value, g);
        }
        finally {
View Full Code Here

    try {
      if (prefixJson) {
        jsonGenerator.writeRaw("{} && ");
      }
      if (isPrettyPrint()) {
        jsonGenerator.useDefaultPrettyPrinter();
      }
      getObjectMapper().writeValue(jsonGenerator, o);
    } catch (JsonGenerationException ex) {
      throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getMessage(), ex);
    }
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.