com.fasterxml.jackson.core.util.DefaultPrettyPrinter.Indenter Java Examples

The following examples show how to use com.fasterxml.jackson.core.util.DefaultPrettyPrinter.Indenter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SnapshotMatcher.java    From json-snapshot.github.io with MIT License 6 votes vote down vote up
private static PrettyPrinter buildDefaultPrettyPrinter() {
  DefaultPrettyPrinter pp =
      new DefaultPrettyPrinter("") {
        @Override
        public DefaultPrettyPrinter withSeparators(Separators separators) {
          this._separators = separators;
          this._objectFieldValueSeparatorWithSpaces =
              separators.getObjectFieldValueSeparator() + " ";
          return this;
        }
      };
  Indenter lfOnlyIndenter = new DefaultIndenter("  ", "\n");
  pp.indentArraysWith(lfOnlyIndenter);
  pp.indentObjectsWith(lfOnlyIndenter);
  return pp;
}
 
Example #2
Source File: AbstractSPARQLJSONWriter.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void startDocument() throws QueryResultHandlerException {
	if (!documentOpen) {
		documentOpen = true;
		headerOpen = false;
		headerComplete = false;
		tupleVariablesFound = false;
		firstTupleWritten = false;
		linksFound = false;

		if (getWriterConfig().get(BasicWriterSettings.PRETTY_PRINT)) {
			// SES-2011: Always use \n for consistency
			Indenter indenter = DefaultIndenter.SYSTEM_LINEFEED_INSTANCE;
			// By default Jackson does not pretty print, so enable this unless
			// PRETTY_PRINT setting is disabled
			DefaultPrettyPrinter pp = new DefaultPrettyPrinter().withArrayIndenter(indenter)
					.withObjectIndenter(indenter);
			jg.setPrettyPrinter(pp);
		}

		try {
			if (getWriterConfig().isSet(BasicQueryWriterSettings.JSONP_CALLBACK)) {
				// SES-1019 : Write the callbackfunction name as a wrapper for
				// the results here
				String callbackName = getWriterConfig().get(BasicQueryWriterSettings.JSONP_CALLBACK);
				jg.writeRaw(callbackName);
				jg.writeRaw("(");
			}
			jg.writeStartObject();
		} catch (IOException e) {
			throw new QueryResultHandlerException(e);
		}
	}
}
 
Example #3
Source File: RDFJSONWriter.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void modelToRdfJsonInternal(final Model graph, final WriterConfig writerConfig,
		final JsonGenerator jg) throws IOException, JsonGenerationException {
	if (writerConfig.get(BasicWriterSettings.PRETTY_PRINT)) {
		// SES-2011: Always use \n for consistency
		Indenter indenter = DefaultIndenter.SYSTEM_LINEFEED_INSTANCE;
		// By default Jackson does not pretty print, so enable this unless
		// PRETTY_PRINT setting is disabled
		DefaultPrettyPrinter pp = new DefaultPrettyPrinter().withArrayIndenter(indenter)
				.withObjectIndenter(indenter);
		jg.setPrettyPrinter(pp);
	}
	jg.writeStartObject();
	for (final Resource nextSubject : graph.subjects()) {
		jg.writeObjectFieldStart(RDFJSONWriter.resourceToString(nextSubject));
		for (final IRI nextPredicate : graph.filter(nextSubject, null, null).predicates()) {
			jg.writeArrayFieldStart(nextPredicate.stringValue());
			for (final Value nextObject : graph.filter(nextSubject, nextPredicate, null).objects()) {
				// contexts are optional, so this may return empty in some
				// scenarios depending on the interpretation of the way contexts
				// work
				final Set<Resource> contexts = graph.filter(nextSubject, nextPredicate, nextObject).contexts();

				RDFJSONWriter.writeObject(nextObject, contexts, jg);
			}
			jg.writeEndArray();
		}
		jg.writeEndObject();
	}
	jg.writeEndObject();
}