Example usage for com.fasterxml.jackson.core JsonGenerator useDefaultPrettyPrinter

List of usage examples for com.fasterxml.jackson.core JsonGenerator useDefaultPrettyPrinter

Introduction

In this page you can find the example usage for com.fasterxml.jackson.core JsonGenerator useDefaultPrettyPrinter.

Prototype

public abstract JsonGenerator useDefaultPrettyPrinter();

Source Link

Document

Convenience method for enabling pretty-printing using the default pretty printer ( com.fasterxml.jackson.core.util.DefaultPrettyPrinter ).

Usage

From source file:uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser.java

/**
 * Serialises an object using the provided json generator.
 *
 * @param object          the object to be serialised and written to file
 * @param jsonGenerator   the {@link com.fasterxml.jackson.core.JsonGenerator} to use to write the object to
 * @param prettyPrint     true if the object should be serialised with pretty printing
 * @param fieldsToExclude optional property names to exclude from the json
 * @throws SerialisationException if the object fails to serialise
 *///from   w  w w . j av a2 s.c om
public void serialise(final Object object, final JsonGenerator jsonGenerator, final boolean prettyPrint,
        final String... fieldsToExclude) throws SerialisationException {
    if (prettyPrint) {
        jsonGenerator.useDefaultPrettyPrinter();
    }

    final ObjectWriter writer = mapper.writer(getFilterProvider(fieldsToExclude));
    try {
        writer.writeValue(jsonGenerator, object);
    } catch (final IOException e) {
        throw new SerialisationException("Failed to serialise object to json: " + e.getMessage(), e);
    }
}