List of usage examples for com.fasterxml.jackson.core JsonGenerator useDefaultPrettyPrinter
public abstract JsonGenerator useDefaultPrettyPrinter();
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); } }