Package org.yaml.snakeyaml

Examples of org.yaml.snakeyaml.Yaml.dump()


        assertEquals("null\n", output);
    }

    public void testNullOutAsEmpty() {
        Yaml yaml = new Yaml(new NullRepresenter());
        String output = yaml.dump(null);
        assertEquals("", output);
    }

    /**
     * test flow style
View Full Code Here


    public void testNullOutAsEmpty2() {
        Yaml yaml = new Yaml(new NullRepresenter());
        Map<String, String> map = new HashMap<String, String>();
        map.put("aaa", "foo");
        map.put("bbb", null);
        String output = yaml.dump(map);
        assertEquals("{aaa: foo, bbb: !!null ''}\n", output);
    }

    /**
     * test block style
View Full Code Here

        options.setDefaultFlowStyle(FlowStyle.BLOCK);
        Yaml yaml = new Yaml(new NullRepresenter(), options);
        Map<String, String> map = new HashMap<String, String>();
        map.put("aaa", "foo");
        map.put("bbb", null);
        String output = yaml.dump(map);
        assertEquals("aaa: foo\nbbb:\n", output);
    }

    private class NullRepresenter extends Representer {
        public NullRepresenter() {
View Full Code Here

        List<String> list = new ArrayList<String>(3);
        list.add(null);
        list.add("value");
        list.add(null);
        Yaml yaml = new Yaml();
        String output = yaml.dump(list);
        assertEquals("Null values must not get anchors and aliases.", "[null, value, null]\n",
                output);
    }
}
View Full Code Here

        List<BigJavaBean> list = new ArrayList<BigJavaBean>();
        list.add(bean1);
        list.add(bean2);
        Yaml yaml = new Yaml(new MyRepresenter());
        yaml.setBeanAccess(BeanAccess.FIELD);
        String output = yaml.dump(list);
        // System.out.println(output);
        // parse back
        @SuppressWarnings("unchecked")
        List<BigJavaBean> parsed = (List<BigJavaBean>) yaml.load(output);
        assertEquals(2, parsed.size());
View Full Code Here

    public void testFloatAsJavaBeanProperty() throws Exception {
        BeanData bean = new BeanData();
        bean.setId("id1");
        bean.setNumber(3.5f);
        Yaml yaml = new Yaml();
        String txt = yaml.dump(bean);
        BeanData parsed = yaml.loadAs(txt, BeanData.class);
        assertEquals(3.5f, parsed.getNumber());
    }

    public void testCompact() {
View Full Code Here

    public void testDump() {
        Académico obj = new Académico();
        obj.setId(1);
        obj.setName("Foo bar baz");
        Yaml yaml = new Yaml();
        String result = yaml.dump(obj);
        assertEquals(PREFIX + "Acad%C3%A9mico {\n  id: 1, name: Foo bar baz}\n", result);
    }

    public void testLoad() {
        Yaml yaml = new Yaml();
View Full Code Here

        mother.setBirthPlace("Saint-Petersburg");
        father.setPartner(mother);
        mother.setPartner(father);
        mother.setBankAccountOwner(father);
        Yaml yaml = new Yaml();
        String output = yaml.dump(father);
        String etalon = Util.getLocalResource("recursive/no-children-1.yaml");
        assertEquals(etalon, output);
        //
        Human father2 = (Human) yaml.load(output);
        assertNotNull(father2);
View Full Code Here

        obj.setId(123);
        obj.setName("Foo bar 123");
        Representer repr = new Representer();
        repr.addClassTag(Académico.class, new Tag("!foo"));
        Yaml yaml = new Yaml(repr);
        String result = yaml.dump(obj);
        assertEquals("!foo {id: 123, name: Foo bar 123}\n", result);
    }

    public void testDumpEscapedTag() {
        Académico obj = new Académico();
View Full Code Here

        obj.setId(123);
        obj.setName("Foo bar 123");
        Representer repr = new Representer();
        repr.addClassTag(Académico.class, new Tag("!Académico"));
        Yaml yaml = new Yaml(repr);
        String result = yaml.dump(obj);
        assertEquals("!Acad%C3%A9mico {id: 123, name: Foo bar 123}\n", result);
    }

    public void testTag() {
        Tag tag = new Tag("!java/javabean:foo.Bar");
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.