public static void main(String[] args) { DumperOptions options = new DumperOptions(); options.setIndent(4); options.setDefaultFlowStyle(FlowStyle.BLOCK); Yaml yaml = new Yaml(options); String dump = yaml.dump(new PerfBenchmarkDriverConf()); System.out.println(dump); } }
public static <K extends Comparable<? super K>, V extends Object> String prettyPrintYaml(Map<K,V> map) { DumperOptions dump = new DumperOptions(); dump.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); dump.setPrettyFlow(true); dump.setIndent(2); dump.setCanonical(false); dump.setExplicitStart(true); Yaml yaml = new Yaml(dump); return yaml.dump(sortByKeys(map)); }
@Override public String saveToString() { yamlOptions.setIndent(options().indent()); yamlOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); yamlOptions.setAllowUnicode(SYSTEM_UTF); yamlRepresenter.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); String header = buildHeader(); String dump = yaml.dump(getValues(false)); if (dump.equals(BLANK_CONFIG)) { dump = ""; } return header + dump; }
public YAMLProcessor(File file, boolean writeDefaults, YAMLFormat format) { super(new LinkedHashMap<>(), writeDefaults); this.format = format; DumperOptions options = new DumperOptions(); options.setIndent(4); options.setDefaultFlowStyle(format.getStyle()); Representer representer = new FancyRepresenter(); representer.setDefaultFlowStyle(format.getStyle()); yaml = new Yaml(new SafeConstructor(), representer, options); this.file = file; }
protected DumperOptions buildDumperOptions(int jsonFeatures, int yamlFeatures, org.yaml.snakeyaml.DumperOptions.Version version) { DumperOptions opt = new DumperOptions(); // would we want canonical? if (Feature.CANONICAL_OUTPUT.enabledIn(_formatFeatures)) { opt.setCanonical(true); } else { opt.setCanonical(false); // if not, MUST specify flow styles opt.setDefaultFlowStyle(FlowStyle.BLOCK); } // split-lines for text blocks? opt.setSplitLines(Feature.SPLIT_LINES.enabledIn(_formatFeatures)); // array indentation? if (Feature.INDENT_ARRAYS.enabledIn(_formatFeatures)) { // But, wrt [dataformats-text#34]: need to set both to diff values to work around bug // (otherwise indentation level is "invisible". Note that this should NOT be necessary // but is needed up to at least SnakeYAML 1.18. // Also looks like all kinds of values do work, except for both being 2... weird. opt.setIndicatorIndent(1); opt.setIndent(2); } // 14-May-2018: [dataformats-text#84] allow use of platform linefeed if (Feature.USE_PLATFORM_LINE_BREAKS.enabledIn(_formatFeatures)) { opt.setLineBreak(DumperOptions.LineBreak.getPlatformLineBreak()); } return opt; }
protected DumperOptions buildDumperOptions(int jsonFeatures, int yamlFeatures, org.yaml.snakeyaml.DumperOptions.Version version) { DumperOptions opt = new DumperOptions(); // would we want canonical? if (Feature.CANONICAL_OUTPUT.enabledIn(_formatFeatures)) { opt.setCanonical(true); } else { opt.setCanonical(false); // if not, MUST specify flow styles opt.setDefaultFlowStyle(FlowStyle.BLOCK); } // split-lines for text blocks? opt.setSplitLines(Feature.SPLIT_LINES.enabledIn(_formatFeatures)); // array indentation? if (Feature.INDENT_ARRAYS.enabledIn(_formatFeatures)) { // But, wrt [dataformats-text#34]: need to set both to diff values to work around bug // (otherwise indentation level is "invisible". Note that this should NOT be necessary // but is needed up to at least SnakeYAML 1.18. // Also looks like all kinds of values do work, except for both being 2... weird. opt.setIndicatorIndent(1); opt.setIndent(2); } // 14-May-2018: [dataformats-text#84] allow use of platform linefeed if (Feature.USE_PLATFORM_LINE_BREAKS.enabledIn(_formatFeatures)) { opt.setLineBreak(DumperOptions.LineBreak.getPlatformLineBreak()); } return opt; }
private void initialize() { yamlOptions.setIndent(DEFAULT_IDENT); yamlOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); }
private static DumperOptions getDumperOptions() { DumperOptions options = new DumperOptions(); options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); options.setIndent(4); options.setAllowReadOnlyProperties(true); options.setExplicitStart(true); return options; }
/** * Construct a new YamlSerializerDeserializer. */ public YamlSerializer() { yamlOptions.setIndent(4); }
public void write(Writer output, Map<String, Object> o, Model model) throws IOException { //TODO improve SnakeYAML API (A. Somov) DumperOptions dumperOptions = new DumperOptions(); dumperOptions.setIndent(2); dumperOptions.setWidth(80); Serializer serializer = new Serializer(new Emitter(output, dumperOptions), new ModelResolver(), dumperOptions, Tag.MAP); Representer representer = new ModelRepresenter(); try { serializer.open(); Node node = representer.represent(model); serializer.serialize(node); serializer.close(); } catch (IOException e) { throw new YAMLException(e); } } }
/** * Sets the level of indentation the resultant loader should use. * * @param indent The indent level * @return This builder (for chaining) */ @NonNull public Builder setIndent(int indent) { options.setIndent(indent); return this; }
private void initialize() { yamlOptions.setIndent(DEFAULT_IDENT); yamlOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); }
@JRubyMethod(visibility = PRIVATE) public IRubyObject initialize(ThreadContext context, IRubyObject io) { options = new DumperOptions(); options.setIndent(2); this.io = io; return context.nil; }
protected DumperOptions getDumperOptions() { DumperOptions options = new DumperOptions(); options.setDefaultFlowStyle(DumperOptions.FlowStyle.FLOW); options.setPrettyFlow(true); options.setIndent(2); return options; }
@JRubyMethod(name = "indentation=") public IRubyObject indentation_set(ThreadContext context, IRubyObject level) { // TODO: unclear if this affects a running emitter options.setIndent((int)level.convertToInteger().getLongValue()); return level; }
protected BaseConfigMapper() { DumperOptions yamlOptions = new DumperOptions(); yamlOptions.setIndent( 2 ); yamlOptions.setDefaultFlowStyle( DumperOptions.FlowStyle.BLOCK ); this.yamlRepresenter.setDefaultFlowStyle( DumperOptions.FlowStyle.BLOCK ); this.yaml = new Yaml( new CustomClassLoaderConstructor( BaseConfigMapper.class.getClassLoader() ), this.yamlRepresenter, yamlOptions ); /* Configure the settings for serializing via the annotations present. */ configureFromSerializeOptionsAnnotation(); }
@Override public String saveToString() { yamlOptions.setIndent(options().indent()); yamlOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); yamlRepresenter.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); String header = buildHeader(); String dump = yaml.dump(getValues(false)); if (dump.equals(BLANK_CONFIG)) { dump = ""; } return header + dump; }
protected DumperOptions getDumperOptions() { DumperOptions options = new DumperOptions(); options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); options.setPrettyFlow(true); options.setIndent(2); options.setSplitLines(false); return options; } }
@JRubyMethod(visibility = PRIVATE) public IRubyObject initialize(ThreadContext context, IRubyObject io, IRubyObject rbOptions) { IRubyObject width = rbOptions.callMethod(context, "line_width"); IRubyObject canonical = rbOptions.callMethod(context, "canonical"); IRubyObject level = rbOptions.callMethod(context, "indentation"); options = new DumperOptions(); options.setCanonical(canonical.isTrue()); options.setIndent((int)level.convertToInteger().getLongValue()); options.setWidth((int)width.convertToInteger().getLongValue()); this.io = io; return context.nil; }
@JRubyMethod(visibility = PRIVATE) public IRubyObject initialize(ThreadContext context, IRubyObject io, IRubyObject rbOptions) { IRubyObject width = rbOptions.callMethod(context, "line_width"); IRubyObject canonical = rbOptions.callMethod(context, "canonical"); IRubyObject level = rbOptions.callMethod(context, "indentation"); options = new DumperOptions(); options.setCanonical(canonical.isTrue()); options.setIndent((int)level.convertToInteger().getLongValue()); options.setWidth((int)width.convertToInteger().getLongValue()); this.io = io; return context.nil; }