Example usage for com.fasterxml.jackson.core.util DefaultPrettyPrinter indentObjectsWith

List of usage examples for com.fasterxml.jackson.core.util DefaultPrettyPrinter indentObjectsWith

Introduction

In this page you can find the example usage for com.fasterxml.jackson.core.util DefaultPrettyPrinter indentObjectsWith.

Prototype

public void indentObjectsWith(Indenter i) 

Source Link

Usage

From source file:com.amazon.feeds.SampleFeedGenerator.java

/**
 * The method for generating sample feeds.
 *
 * @param format The class containing the format specifications.
 * @param items The number of items to generate.
 * @param ext File extension./*  w  ww.java 2  s .  c  om*/
 */
public void createSampleFeed(IFeedFormat format, int items, String ext) throws Exception {

    ObjectMapper mapper = new ObjectMapper();
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);

    mapper.getFactory().setCharacterEscapes(format.getEscapeRules());

    // create output file
    String out = format.getFeedFormat() + "-" + items + "." + ext;
    // TODO: add XML support

    File outFile = new File(SAMPLE_PATH, out);
    if (!outFile.exists()) {
        outFile.getParentFile().mkdirs();
    }

    // populate sample feed
    System.out.println("Generating " + items + (items == 1 ? " item" : " items") + " for "
            + format.getProvider() + " feed at " + outFile.getAbsolutePath());
    format.populate(items);

    // write JSON to file
    if (format.usePrettyPrint()) {

        DefaultPrettyPrinter.Indenter indenter = new DefaultIndenter("   ", DefaultIndenter.SYS_LF);
        DefaultPrettyPrinter printer = new DefaultPrettyPrinter();
        printer.indentObjectsWith(indenter);
        printer.indentArraysWith(indenter);
        mapper.writer(printer).writeValue(outFile, format);
    } else {
        mapper.writeValue(outFile, format);
    }
}

From source file:org.wrml.runtime.format.application.json.JsonModelPrinter.java

public JsonModelPrinter(final JsonGenerator jsonGenerator, final ModelWriteOptions writeOptions) {

    _JsonGenerator = jsonGenerator;/* w ww  . j  av  a  2 s.  c  o  m*/
    _WriteOptions = writeOptions;

    if (_WriteOptions.isPrettyPrint()) {
        final DefaultPrettyPrinter prettyPrinter = new DefaultPrettyPrinter();
        prettyPrinter.indentObjectsWith(new DefaultPrettyPrinter.Lf2SpacesIndenter());
        prettyPrinter.indentArraysWith(new DefaultPrettyPrinter.Lf2SpacesIndenter());
        _JsonGenerator.setPrettyPrinter(prettyPrinter);

        // _JsonGenerator.useDefaultPrettyPrinter();
    }
}