com.fasterxml.jackson.core.PrettyPrinter Java Examples

The following examples show how to use com.fasterxml.jackson.core.PrettyPrinter. 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: AutodetectPrettyPrintingMarker.java    From logbook with MIT License 6 votes vote down vote up
@Override
protected void writeFieldValue(final JsonGenerator generator) throws IOException {
    final PrettyPrinter prettyPrinter = generator.getPrettyPrinter();

    if (prettyPrinter == null) {
        super.writeFieldValue(generator);
    } else {
        final JsonFactory factory = generator.getCodec().getFactory();

        // append to existing tree event by event
        try (final JsonParser parser = factory.createParser(super.getFieldValue().toString())) {
            while (parser.nextToken() != null) {
                generator.copyCurrentEvent(parser);
            }
        }
    }
}
 
Example #2
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 #3
Source File: JSONIO.java    From pom-manipulation-ext with Apache License 2.0 6 votes vote down vote up
public void writeJSON( File target, DocumentContext contents ) throws ManipulationException
{
    try
    {
        PrettyPrinter dpp = new MyPrettyPrinter( getCharset() );
        ObjectMapper mapper = new ObjectMapper();
        String jsonString = contents.jsonString();
        String pretty = mapper.writer( dpp ).writeValueAsString( mapper.readValue( jsonString, Object.class ) );
        Charset cs = getCharset();
        FileOutputStream fileOutputStream = new FileOutputStream( target );
        try (OutputStreamWriter p = new OutputStreamWriter( fileOutputStream, cs ) )
        {
            p.write( pretty );
            p.append( getEOL() );
        }
    }
    catch ( IOException e )
    {
        logger.error( "Unable to write JSON string:  ", e );
        throw new ManipulationException( "Unable to write JSON string", e );
    }
}
 
Example #4
Source File: GenerateConnectorInspectionsMojo.java    From syndesis with Apache License 2.0 6 votes vote down vote up
public static DataShape generateInspections(URL[] classpath, DataShape shape) throws IOException, ClassNotFoundException {
    JavaClass c = inspect(classpath, shape);

    List<DataShape> variants = new ArrayList<>(shape.getVariants().size());
    for (DataShape s : shape.getVariants()) {
        variants.add(generateInspections(classpath, s));
    }

    String inspection = io.atlasmap.v2.Json.mapper().writer((PrettyPrinter) null).writeValueAsString(c);
    return new DataShape.Builder()
        .createFrom(shape)
        .specification(inspection)
        .variants(variants)
        .compress()
        .build();
}
 
Example #5
Source File: SnapshotMatcher.java    From json-snapshot.github.io with MIT License 5 votes vote down vote up
static Function<Object, String> defaultJsonFunction() {

    ObjectMapper objectMapper = buildObjectMapper();

    PrettyPrinter pp = buildDefaultPrettyPrinter();

    return (object) -> {
      try {
        return objectMapper.writer(pp).writeValueAsString(object);
      } catch (Exception e) {
        throw new SnapshotMatchException(e.getMessage());
      }
    };
  }
 
Example #6
Source File: FhirMetadataRetrieval.java    From syndesis with Apache License 2.0 5 votes vote down vote up
static String includeResources(String specification, String... resourceTypes) throws IOException {
    if (resourceTypes != null && resourceTypes.length != 0) {
        XmlDocument document = MAPPER.readValue(specification, XmlDocument.class);
        includeResources(null, document, resourceTypes);
        return MAPPER.writer((PrettyPrinter) null).writeValueAsString(document);
    }

    return specification;
}
 
Example #7
Source File: ObjectMappers.java    From glowroot with Apache License 2.0 4 votes vote down vote up
public static PrettyPrinter getPrettyPrinter() {
    CustomPrettyPrinter prettyPrinter = new CustomPrettyPrinter();
    prettyPrinter.indentArraysWith(DefaultIndenter.SYSTEM_LINEFEED_INSTANCE);
    return prettyPrinter;
}
 
Example #8
Source File: MessageMarshaller.java    From curiostack with MIT License 4 votes vote down vote up
private MessageMarshaller(@Nullable PrettyPrinter prettyPrinter, MarshallerRegistry registry) {
  this.prettyPrinter = prettyPrinter;
  this.registry = registry;
}
 
Example #9
Source File: ExtendedObjectWriter.java    From log4j2-elasticsearch with Apache License 2.0 4 votes vote down vote up
public ExtendedObjectWriter(ObjectMapper objectMapper, SerializationConfig config, JavaType rootType, PrettyPrinter pp) {
    super(objectMapper, config, rootType, pp);
}
 
Example #10
Source File: ExtendedObjectMapper.java    From log4j2-elasticsearch with Apache License 2.0 4 votes vote down vote up
public ObjectWriter _newWriter(SerializationConfig config, JavaType rootType, PrettyPrinter pp) {
    return new ExtendedObjectWriter(this, config, rootType, pp);
}
 
Example #11
Source File: Jackson2JsonEncoder.java    From java-technology-stack with MIT License 4 votes vote down vote up
private static PrettyPrinter initSsePrettyPrinter() {
	DefaultPrettyPrinter printer = new DefaultPrettyPrinter();
	printer.indentObjectsWith(new DefaultIndenter("  ", "\ndata:"));
	return printer;
}
 
Example #12
Source File: YamlJacksonFactory.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@Override
protected PrettyPrinter newCompactPrinter() {
    return new MinimalPrettyPrinter();
}
 
Example #13
Source File: YamlJacksonFactory.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@Override
protected PrettyPrinter newPrettyPrinter() {
    return new DefaultPrettyPrinter();
}
 
Example #14
Source File: XmlJacksonFactory.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@Override
protected PrettyPrinter newCompactPrinter() {
    // Yes, null is the proper answer.
    return null;
}
 
Example #15
Source File: XmlJacksonFactory.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@Override
protected PrettyPrinter newPrettyPrinter() {
    return new Log4jXmlPrettyPrinter(DEFAULT_INDENT);
}
 
Example #16
Source File: JsonJacksonFactory.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@Override
protected PrettyPrinter newCompactPrinter() {
    return new MinimalPrettyPrinter();
}
 
Example #17
Source File: JsonJacksonFactory.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@Override
protected PrettyPrinter newPrettyPrinter() {
    return new DefaultPrettyPrinter();
}
 
Example #18
Source File: JsonJacksonFactory.java    From curiostack with MIT License 4 votes vote down vote up
@Override
protected PrettyPrinter newPrettyPrinter() {
  return new DefaultPrettyPrinter();
}
 
Example #19
Source File: JsonJacksonFactory.java    From curiostack with MIT License 4 votes vote down vote up
@Override
protected PrettyPrinter newCompactPrinter() {
  return new MinimalPrettyPrinter();
}
 
Example #20
Source File: FilterObjectWriter.java    From jfilter with Apache License 2.0 4 votes vote down vote up
public ObjectWriter with(PrettyPrinter pp) {
    return new FilterObjectWriter(this, _config, _generatorSettings.with(pp), _prefetch);
}
 
Example #21
Source File: JacksonFactory.java    From summerframework with Apache License 2.0 4 votes vote down vote up
@Override
protected PrettyPrinter newPrettyPrinter() {
    return new DefaultPrettyPrinter();
}
 
Example #22
Source File: JacksonFactory.java    From summerframework with Apache License 2.0 4 votes vote down vote up
@Override
protected PrettyPrinter newCompactPrinter() {
    return new MinimalPrettyPrinter();
}
 
Example #23
Source File: Jackson2JsonEncoder.java    From spring-analysis-note with MIT License 4 votes vote down vote up
private static PrettyPrinter initSsePrettyPrinter() {
	DefaultPrettyPrinter printer = new DefaultPrettyPrinter();
	printer.indentObjectsWith(new DefaultIndenter("  ", "\ndata:"));
	return printer;
}
 
Example #24
Source File: JCalRawWriter.java    From biweekly with BSD 2-Clause "Simplified" License 2 votes vote down vote up
/**
 * Sets the pretty printer to pretty-print the JSON with. Note that this
 * method implicitly enables indenting, so {@code setPrettyPrint(true)} does
 * not also need to be called.
 * @param prettyPrinter the custom pretty printer (defaults to an instance
 * of {@link JCalPrettyPrinter}, if {@code setPrettyPrint(true)} has been
 * called)
 */
public void setPrettyPrinter(PrettyPrinter prettyPrinter) {
	prettyPrint = true;
	this.prettyPrinter = prettyPrinter;
}
 
Example #25
Source File: AbstractJacksonBackedJsonSerializer.java    From springboot-shiro-cas-mybatis with MIT License 2 votes vote down vote up
/**
 * Instantiates a new Registered service json serializer.
 *
 * @param objectMapper  the object mapper
 * @param prettyPrinter the pretty printer
 */
public AbstractJacksonBackedJsonSerializer(final ObjectMapper objectMapper, final PrettyPrinter prettyPrinter) {
    this.objectMapper = objectMapper;
    this.prettyPrinter = prettyPrinter;
}
 
Example #26
Source File: AbstractJacksonBackedJsonSerializer.java    From springboot-shiro-cas-mybatis with MIT License 2 votes vote down vote up
/**
 * Instantiates a new Registered service json serializer.
 *
 * @param prettyPrinter the pretty printer
 */
public AbstractJacksonBackedJsonSerializer(final PrettyPrinter prettyPrinter) {
    this.objectMapper = initializeObjectMapper();
    this.prettyPrinter = prettyPrinter;
}
 
Example #27
Source File: AbstractJacksonFactory.java    From curiostack with MIT License votes vote down vote up
protected abstract PrettyPrinter newPrettyPrinter(); 
Example #28
Source File: AbstractJacksonFactory.java    From curiostack with MIT License votes vote down vote up
protected abstract PrettyPrinter newCompactPrinter(); 
Example #29
Source File: JacksonFactory.java    From summerframework with Apache License 2.0 votes vote down vote up
abstract protected PrettyPrinter newPrettyPrinter(); 
Example #30
Source File: AbstractJacksonFactory.java    From logging-log4j2 with Apache License 2.0 votes vote down vote up
abstract protected PrettyPrinter newCompactPrinter();