use of com.fasterxml.jackson.core.util.DefaultPrettyPrinter.Indenter in project rdf4j by eclipse.
the class RDFJSONWriter method modelToRdfJsonInternal.
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();
}
use of com.fasterxml.jackson.core.util.DefaultPrettyPrinter.Indenter in project rdf4j by eclipse.
the class AbstractSPARQLJSONWriter method startDocument.
@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);
}
}
}
Aggregations