public StreamingRepresentationFormat usePrettyPrinter() { g.useDefaultPrettyPrinter(); return this; }
@Override public JsonGenerator useDefaultPrettyPrinter() { delegate.useDefaultPrettyPrinter(); return this; }
public void usePrettyPrint() { generator.useDefaultPrettyPrinter(); }
public static String createJsonFrom( Object data ) throws JsonBuildRuntimeException { try { StringWriter writer = new StringWriter(); try { JsonGenerator generator = OBJECT_MAPPER.getJsonFactory() .createJsonGenerator( writer ) .useDefaultPrettyPrinter(); writeValue( generator, data ); } finally { writer.close(); } return writer.getBuffer().toString(); } catch ( IOException e ) { throw new JsonBuildRuntimeException( e ); } }
/** Render this as <a href="http://json.org/">JSON</a>. * @param pretty if true, pretty-print JSON. */ public String toString(boolean pretty) { try { StringWriter writer = new StringWriter(); JsonGenerator gen = Schema.FACTORY.createJsonGenerator(writer); if (pretty) gen.useDefaultPrettyPrinter(); toJson(gen); gen.flush(); return writer.toString(); } catch (IOException e) { throw new AvroRuntimeException(e); } } void toJson(JsonGenerator gen) throws IOException {
/** Render this as <a href="http://json.org/">JSON</a>. * @param pretty if true, pretty-print JSON. */ public String toString(boolean pretty) { try { StringWriter writer = new StringWriter(); JsonGenerator gen = FACTORY.createJsonGenerator(writer); if (pretty) gen.useDefaultPrettyPrinter(); toJson(new Names(), gen); gen.flush(); return writer.toString(); } catch (IOException e) { throw new AvroRuntimeException(e); } }
jg.useDefaultPrettyPrinter(); jg.writeStartObject();
@Override public void run() { try { ObjectName q = null; if (query != null) { q = new ObjectName(query); } MBeanServerConnection jmx = conn.getMServer(); JsonFactory jsonFactory = new JsonFactory(); JsonGenerator jg = jsonFactory.createJsonGenerator(System.out); jg.useDefaultPrettyPrinter(); jg.writeStartObject(); listBeans(q, jg, jmx); jg.writeEndObject(); jg.close(); System.out.println(); System.out.flush(); } catch (Exception e) { host.fail(e.toString()); } }
jg = jsonFactory.createJsonGenerator(writer); jg.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET); jg.useDefaultPrettyPrinter(); jg.writeStartObject();
jg = jsonFactory.createJsonGenerator(writer); jg.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET); jg.useDefaultPrettyPrinter(); jg.writeStartObject(); if (parent != null && parent instanceof CompositeService) {
@Override public JsonGenerator useDefaultPrettyPrinter() { delegate.useDefaultPrettyPrinter(); return this; }
public WriteJsonResult(final ComponentLog logger, final RecordSchema recordSchema, final SchemaAccessWriter schemaAccess, final OutputStream out, final boolean prettyPrint, final NullSuppression nullSuppression, final OutputGrouping outputGrouping, final String dateFormat, final String timeFormat, final String timestampFormat, final String mimeType) throws IOException { super(out); this.logger = logger; this.recordSchema = recordSchema; this.schemaAccess = schemaAccess; this.nullSuppression = nullSuppression; this.outputGrouping = outputGrouping; this.mimeType = mimeType; final DateFormat df = dateFormat == null ? null : DataTypeUtils.getDateFormat(dateFormat); final DateFormat tf = timeFormat == null ? null : DataTypeUtils.getDateFormat(timeFormat); final DateFormat tsf = timestampFormat == null ? null : DataTypeUtils.getDateFormat(timestampFormat); LAZY_DATE_FORMAT = () -> df; LAZY_TIME_FORMAT = () -> tf; LAZY_TIMESTAMP_FORMAT = () -> tsf; this.generator = factory.createJsonGenerator(out); if (prettyPrint) { generator.useDefaultPrettyPrinter(); } else if (OutputGrouping.OUTPUT_ONELINE.equals(outputGrouping)) { // Use a minimal pretty printer with a newline object separator, will output one JSON object per line generator.setPrettyPrinter(new MinimalPrettyPrinter("\n")); } }
protected final void _configAndWriteValue(JsonGenerator jgen, Object value, Class<?> viewClass) throws IOException, JsonGenerationException, JsonMappingException { SerializationConfig cfg = copySerializationConfig().withView(viewClass); if (cfg.isEnabled(SerializationConfig.Feature.INDENT_OUTPUT)) { jgen.useDefaultPrettyPrinter(); } // [JACKSON-282]: consider Closeable if (cfg.isEnabled(SerializationConfig.Feature.CLOSE_CLOSEABLE) && (value instanceof Closeable)) { _configAndWriteCloseable(jgen, value, cfg); return; } boolean closed = false; try { _serializerProvider.serializeValue(cfg, jgen, value, _serializerFactory); closed = true; jgen.close(); } finally { if (!closed) { try { jgen.close(); } catch (IOException ioe) { } } } }
@Override public JsonGenerator useDefaultPrettyPrinter() { return generator.useDefaultPrettyPrinter(); }
@Override public JsonGenerator useDefaultPrettyPrinter() { return generator.useDefaultPrettyPrinter(); }
@Override public JsonGenerator useDefaultPrettyPrinter() { return generator.useDefaultPrettyPrinter(); }
jgen.setPrettyPrinter((pp == NULL_PRETTY_PRINTER) ? null : pp); } else if (_config.isEnabled(SerializationConfig.Feature.INDENT_OUTPUT)) { jgen.useDefaultPrettyPrinter();
jg = jsonFactory.createJsonGenerator(writer); jg.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET); jg.useDefaultPrettyPrinter(); jg.writeStartObject(); if (registry.isDynamic()) {
/** * Write the actual JSON content to the stream. * @param stream the output stream to use * @param value the value to be rendered, as returned from {@link #filterModel} * @param jsonPrefix the prefix for this view's JSON output * (as indicated through {@link #setJsonPrefix}/{@link #setPrefixJson}) * @throws IOException if writing failed */ protected void writeContent(OutputStream stream, Object value, String jsonPrefix) throws IOException { JsonGenerator generator = this.objectMapper.getJsonFactory().createJsonGenerator(stream, this.encoding); // A workaround for JsonGenerators not applying serialization features // https://github.com/FasterXML/jackson-databind/issues/12 if (this.objectMapper.getSerializationConfig().isEnabled(SerializationConfig.Feature.INDENT_OUTPUT)) { generator.useDefaultPrettyPrinter(); } if (jsonPrefix != null) { generator.writeRaw(jsonPrefix); } this.objectMapper.writeValue(generator, value); }