Java Code Examples for org.yaml.snakeyaml.Yaml#dumpAs()

The following examples show how to use org.yaml.snakeyaml.Yaml#dumpAs() . 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: UuidSupportTest.java    From snake-yaml with Apache License 2.0 5 votes vote down vote up
@Test
public void dumpBean() {
    BeanWithId bean = new BeanWithId();
    bean.setValue(3);
    UUID uuid = UUID.fromString("ac4877be-0c31-4458-a86e-0272efe1aaa8");
    bean.setId(uuid);
    Yaml yaml = new Yaml();
    String output = yaml.dumpAs(bean, Tag.MAP, DumperOptions.FlowStyle.BLOCK);
    String expected = Util.getLocalResource("issues/issue306-2.yaml");
    assertEquals(expected, output);
}
 
Example 2
Source File: BooleanEnumTest.java    From snake-yaml with Apache License 2.0 5 votes vote down vote up
@Test
public void dumpEnum() {

    BeanWithEnum bean = new BeanWithEnum(true, "10", BooleanEnum.TRUE);
    Yaml yaml = new Yaml(new MyConstructor(), new MyRepresenter());
    String output = yaml.dumpAs(bean, Tag.MAP, DumperOptions.FlowStyle.FLOW);
    assertEquals("{boolField: true, enumField: 'true', name: '10'}\n", output);
}
 
Example 3
Source File: ArrayInGenericCollectionTest.java    From snake-yaml with Apache License 2.0 5 votes vote down vote up
public void testNoTags() {
    Yaml yaml2dump = new Yaml();
    yaml2dump.setBeanAccess(BeanAccess.FIELD);
    B data = createB();
    String dump = yaml2dump.dumpAs(data, Tag.MAP, FlowStyle.AUTO);
    // System.out.println(dump);
    assertEquals("meta:\n- [whatever]\n- [something, something else]\n", dump);
    //
    Constructor constr = new Constructor(B.class);
    Yaml yaml2load = new Yaml(constr);
    yaml2load.setBeanAccess(BeanAccess.FIELD);
    B loaded = (B) yaml2load.load(dump);

    Assert.assertArrayEquals(data.meta.toArray(), loaded.meta.toArray());
}
 
Example 4
Source File: DumpTest.java    From snake-yaml with Apache License 2.0 5 votes vote down vote up
public void testDumperNullStyle2() {
    DumperOptions options = new DumperOptions();
    options.setDefaultFlowStyle(FlowStyle.BLOCK);
    Yaml yaml = new Yaml(options);
    Bean124 bean = new Bean124();
    String output1 = yaml.dumpAs(bean, new Tag("!!foo2.bar2"), null);
    assertEquals("!!foo2.bar2\na: aaa\nnumbers:\n- 1\n- 2\n- 3\n", output1);
}
 
Example 5
Source File: DumpTest.java    From snake-yaml with Apache License 2.0 5 votes vote down vote up
public void testDumperNullTag() {
    Yaml yaml = new Yaml();
    Bean124 bean = new Bean124();
    String output1 = yaml.dumpAs(bean, null, FlowStyle.BLOCK);
    assertEquals(
            "!!org.yaml.snakeyaml.issues.issue124.Bean124\na: aaa\nnumbers:\n- 1\n- 2\n- 3\n",
            output1);
}
 
Example 6
Source File: DumpTest.java    From snake-yaml with Apache License 2.0 4 votes vote down vote up
public void testDumperDifferentTag() {
    Yaml yaml = new Yaml();
    Bean124 bean = new Bean124();
    String output1 = yaml.dumpAs(bean, new Tag("!!foo.bar"), FlowStyle.BLOCK);
    assertEquals("!!foo.bar\na: aaa\nnumbers:\n- 1\n- 2\n- 3\n", output1);
}
 
Example 7
Source File: DumpTest.java    From snake-yaml with Apache License 2.0 4 votes vote down vote up
public void testDumperFlowStyle() {
    Yaml yaml = new Yaml();
    Bean124 bean = new Bean124();
    String output1 = yaml.dumpAs(bean, new Tag("!!foo.bar"), FlowStyle.FLOW);
    assertEquals("!!foo.bar {a: aaa, numbers: [1, 2, 3]}\n", output1);
}
 
Example 8
Source File: DumpTest.java    From snake-yaml with Apache License 2.0 4 votes vote down vote up
public void testDumperAutoStyle() {
    Yaml yaml = new Yaml();
    Bean124 bean = new Bean124();
    String output1 = yaml.dumpAs(bean, new Tag("!!foo.bar"), FlowStyle.AUTO);
    assertEquals("!!foo.bar\na: aaa\nnumbers: [1, 2, 3]\n", output1);
}
 
Example 9
Source File: DumpTest.java    From snake-yaml with Apache License 2.0 4 votes vote down vote up
public void testDumperNullStyle() {
    Yaml yaml = new Yaml();
    Bean124 bean = new Bean124();
    String output1 = yaml.dumpAs(bean, new Tag("!!foo.bar"), null);
    assertEquals("!!foo.bar\na: aaa\nnumbers: [1, 2, 3]\n", output1);
}