Java Code Examples for org.yaml.snakeyaml.DumperOptions#setWidth()

The following examples show how to use org.yaml.snakeyaml.DumperOptions#setWidth() . 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: MoreImmutablesTest.java    From snake-yaml with Apache License 2.0 6 votes vote down vote up
public void testMatteBorder() {
    DumperOptions options = new DumperOptions();
    options.setWidth(400);
    Yaml yaml = new Yaml(new ImmutablesRepresenter(), options);
    Insets insets = new Insets(10, 20, 30, 40);
    Color color = new Color(100, 150, 200);
    MatteBorder border = BorderFactory.createMatteBorder(insets.top, insets.left,
            insets.bottom, insets.right, color);
    String dump = yaml.dump(border);
    assertEquals(
            "!!javax.swing.border.MatteBorder [!!java.awt.Insets [10, 20, 30, 40], !!java.awt.Color [100, 150, 200, 255]]\n",
            dump);
    Object loaded = yaml.load(dump);
    assertTrue(loaded instanceof MatteBorder);
    MatteBorder loadedBorder = (MatteBorder) loaded;
    assertEquals(insets, loadedBorder.getBorderInsets());
    assertEquals(color, loadedBorder.getMatteColor());
}
 
Example 2
Source File: ClusterDefinitionService.java    From karamel with Apache License 2.0 6 votes vote down vote up
public static String jsonToYaml(JsonCluster jsonCluster) throws KaramelException {
  YamlCluster yamlCluster = new YamlCluster(jsonCluster);
  DumperOptions options = new DumperOptions();
  options.setIndent(2);
  options.setWidth(120);
  options.setExplicitEnd(false);
  options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
  options.setPrettyFlow(true);
  options.setDefaultScalarStyle(DumperOptions.ScalarStyle.PLAIN);
  YamlPropertyRepresenter yamlPropertyRepresenter = new YamlPropertyRepresenter();
  yamlPropertyRepresenter.addClassTag(YamlCluster.class, Tag.MAP);
  yamlPropertyRepresenter.addClassTag(Ec2.class, Tag.MAP);
  yamlPropertyRepresenter.addClassTag(Baremetal.class, Tag.MAP);
  yamlPropertyRepresenter.addClassTag(Gce.class, Tag.MAP);
  yamlPropertyRepresenter.addClassTag(Nova.class, Tag.MAP);
  yamlPropertyRepresenter.addClassTag(Occi.class, Tag.MAP);
  yamlPropertyRepresenter.addClassTag(Cookbook.class, Tag.MAP);
  yamlPropertyRepresenter.addClassTag(YamlGroup.class, Tag.MAP);
  yamlPropertyRepresenter.addClassTag(HashSet.class, Tag.MAP);
  Yaml yaml = new Yaml(yamlPropertyRepresenter, options);
  String content = yaml.dump(yamlCluster);
  return content;
}
 
Example 3
Source File: Autogen.java    From deploymentmanager-autogen with Apache License 2.0 5 votes vote down vote up
private static String toYaml(Map<String, Object> message) {
  DumperOptions dumperOptions = new DumperOptions();
  dumperOptions.setDefaultFlowStyle(FlowStyle.BLOCK);
  dumperOptions.setWidth(3000);  // No auto line breaking on a field.
  return new Yaml(new SafeConstructor(), new Representer(), dumperOptions)
      .dump(message)
      .trim();
}
 
Example 4
Source File: LineBreakDooubleQuotedTest.java    From snake-yaml with Apache License 2.0 5 votes vote down vote up
public void testDoubleQuotedStyle() {
    DumperOptions options = new DumperOptions();
    options.setDefaultScalarStyle(ScalarStyle.DOUBLE_QUOTED);
    options.setWidth(20);
    options.setIndent(4);
    Yaml yaml = new Yaml(options);
    String etalon = "12345678901234567890\n\n123  456";
    String output = yaml.dump(etalon);
    // System.out.println(output);
    assertEquals("\"12345678901234567890\\n\\\n    \\n123  456\"\n", output);
    String parsed = (String) yaml.load(output);
    assertEquals(etalon, parsed);
}
 
Example 5
Source File: LineBreakDooubleQuotedTest.java    From snake-yaml with Apache License 2.0 5 votes vote down vote up
public void testDoubleQuotedStyleNoLineSplit() {
    DumperOptions options = new DumperOptions();
    options.setDefaultScalarStyle(ScalarStyle.DOUBLE_QUOTED);
    options.setWidth(20);
    options.setSplitLines(false);
    options.setIndent(4);
    Yaml yaml = new Yaml(options);
    String etalon = "12345678901234567890\n\n123  456";
    String output = yaml.dump(etalon);
    // System.out.println(output);
    assertEquals("\"12345678901234567890\\n\\n123  456\"\n", output);
    String parsed = (String) yaml.load(output);
    assertEquals(etalon, parsed);
}
 
Example 6
Source File: FlexibleScalarStyleTest.java    From snake-yaml with Apache License 2.0 5 votes vote down vote up
public void testNoFoldedScalar() {
    DumperOptions options = new DumperOptions();
    options.setWidth(30);
    Yaml yaml = new Yaml(options);
    String output = yaml.dump(getData());
    // System.out.println(output);
    String etalon = Util.getLocalResource("representer/scalar-style1.yaml");
    assertEquals(etalon, output);
}
 
Example 7
Source File: FlexibleScalarStyleTest.java    From snake-yaml with Apache License 2.0 5 votes vote down vote up
public void testCustomScalarStyle() {
    DumperOptions options = new DumperOptions();
    options.setWidth(30);
    Yaml yaml = new Yaml(new MyRepresenter(), options);
    String output = yaml.dump(getData());
    // System.out.println(output);
    String etalon = Util.getLocalResource("representer/scalar-style2.yaml");
    assertEquals(etalon, output);
}
 
Example 8
Source File: FlexibleScalarStyleTest.java    From snake-yaml with Apache License 2.0 5 votes vote down vote up
public void testCustomScalarStyleNoSplitLines() {
    DumperOptions options = new DumperOptions();
    options.setWidth(30);
    options.setSplitLines(false);
    Yaml yaml = new Yaml(new MyRepresenter(), options);
    String output = yaml.dump(getData());
    // System.out.println(output);
    String etalon = Util.getLocalResource("representer/scalar-style3.yaml");
    assertEquals(etalon, output);
}
 
Example 9
Source File: DumpStackTraceTest.java    From snake-yaml with Apache License 2.0 5 votes vote down vote up
public void testJavaStackTraceWithNoSpecialCharacters() {
    DumperOptions options = new DumperOptions();
    options.setWidth(50);
    Yaml yaml = new Yaml(options);
    String input = Util.getLocalResource("representer/stacktrace2.txt");
    assertEquals(-1, input.indexOf(':'));
    assertEquals(-1, input.indexOf('\t'));
    String result = yaml.dump(input);
    // System.out.println(result);
    assertEquals(result, yaml.dump(yaml.load(result)));
}
 
Example 10
Source File: SoyDirectives.java    From deploymentmanager-autogen with Apache License 2.0 4 votes vote down vote up
@Inject
YamlPrimitive() {
  dumperOptions = new DumperOptions();
  dumperOptions.setWidth(2048);  // Avoid auto-line breaking, unless it's really long.
}