com.fasterxml.jackson.core.util.Separators Java Examples

The following examples show how to use com.fasterxml.jackson.core.util.Separators. 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: JsonFormatter.java    From formatter-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public void init(Map<String, String> options, ConfigurationSource cfg) {
    super.initCfg(cfg);

    int indent = Integer.parseInt(options.getOrDefault("indent", "4"));
    String lineEnding = options.getOrDefault("lineending", System.lineSeparator());
    boolean spaceBeforeSeparator = Boolean.parseBoolean(options.getOrDefault("spaceBeforeSeparator", "true"));

    formatter = new ObjectMapper();

    // Setup a pretty printer with an indenter (indenter has 4 spaces in this case)
    DefaultPrettyPrinter.Indenter indenter = new DefaultIndenter(Strings.repeat(" ", indent), lineEnding);
    DefaultPrettyPrinter printer = new DefaultPrettyPrinter() {
        private static final long serialVersionUID = 1L;

        @Override
        public DefaultPrettyPrinter createInstance() {
            return new DefaultPrettyPrinter(this);
        }

        @Override
        public DefaultPrettyPrinter withSeparators(Separators separators) {
            this._separators = separators;
            this._objectFieldValueSeparatorWithSpaces = (spaceBeforeSeparator ? " " : "")
                    + separators.getObjectFieldValueSeparator() + " ";
            return this;
        }
    };

    printer.indentObjectsWith(indenter);
    printer.indentArraysWith(indenter);
    formatter.setDefaultPrettyPrinter(printer);
    formatter.enable(SerializationFeature.INDENT_OUTPUT);
}