Package org.yaml.snakeyaml

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


    public void testDumpBlock() {
        DumperOptions options = new DumperOptions();
        options.setAllowReadOnlyProperties(true);
        options.setDefaultFlowStyle(FlowStyle.BLOCK);
        Yaml yaml = new Yaml(new SetRepresenter(), options);
        String output = yaml.dump(createBlog());
        // System.out.println(output);
        assertEquals(Util.getLocalResource("issues/issue73-dump8.txt"), output);
        //
        check(output);
    }
View Full Code Here


        labels.add("SnakeYAML");
        blog.setLabels(labels);
        DumperOptions options = new DumperOptions();
        options.setAllowReadOnlyProperties(true);
        Yaml yaml = new Yaml(options);
        String output = yaml.dump(blog);
        // System.out.println(output);
        assertEquals(Util.getLocalResource("issues/issue73-1.txt"), output);
    }

    public void testLoad() {
View Full Code Here

        list.add("zzz");
        list.add("xxx");
        list.add("ccc");
        bean.setSet(list);
        Yaml yaml = new Yaml();
        String doc = yaml.dump(bean);
        // System.out.println(doc);
        //
        Bean1 loaded = (Bean1) yaml.load(doc);
        assertEquals(3, loaded.getSet().size());
        assertEquals(TreeSet.class, loaded.getSet().getClass());
View Full Code Here

        Set<Object> set2 = new HashSet<Object>();
        set1.add(set2);
        set2.add(set1);
        Yaml yaml = new Yaml();
        try {
            yaml.dump(set1);
            fail("Recursive sets are not supported.");
        } catch (StackOverflowError e) {
            assertEquals(null, e.getMessage());
        }
    }
View Full Code Here

        bean.setSet(set);
        set.add("ggg");
        set.add("hhh");
        set.add(bean);
        Yaml yaml = new Yaml();
        String doc = yaml.dump(bean);
        // System.out.println(doc);
        assertEquals(Util.getLocalResource("issues/issue73-recursive9.txt"), doc);
    }

    public void testLoadException() {
View Full Code Here

        list.add("zzz");
        list.add("xxx");
        list.add("ccc");
        bean.setList(list);
        Yaml yaml = new Yaml();
        String doc = yaml.dump(bean);
        // System.out.println(doc);
        Bean1 loaded = (Bean1) yaml.load(doc);
        assertEquals(3, loaded.getList().size());
        assertEquals(ArrayList.class, loaded.getList().getClass());
    }
View Full Code Here

        }
        car.setWheels(wheels);
        DumperOptions options = new DumperOptions();
        options.setDefaultFlowStyle(FlowStyle.BLOCK);
        Yaml yaml = new Yaml(options);
        assertEquals(Util.getLocalResource("constructor/cararray-with-tags.yaml"), yaml.dump(car));
    }

    public void testLoadClassTag() {
        Constructor constructor = new Constructor();
        constructor.addTypeDescription(new TypeDescription(Car.class, "!car"));
View Full Code Here

    public void testRepresentor() {
        BigDecimalJavaBean bean = new BigDecimalJavaBean();
        bean.setAmount(1.5f);
        bean.setNumber(new BigDecimal("3.1416"));
        Yaml yaml = new Yaml();
        String output = yaml.dump(bean);
        String className = this.getClass().getPackage().getName();
        assertEquals("!!" + className + ".BigDecimalJavaBean {amount: 1.5, number: 3.1416}\n",
                output);
    }
View Full Code Here

    public void testDumpList() {
        List<Integer> l = new ArrayList<Integer>(2);
        l.add(1);
        l.add(2);
        Yaml yaml = new Yaml();
        String result = yaml.dump(l);
        assertEquals("[1, 2]\n", result);
    }

    public void testDumpListSameIntegers() {
        List<Integer> l = new ArrayList<Integer>(2);
View Full Code Here

    public void testDumpListSameIntegers() {
        List<Integer> l = new ArrayList<Integer>(2);
        l.add(1);
        l.add(1);
        Yaml yaml = new Yaml();
        String result = yaml.dump(l);
        assertEquals("[1, 1]\n", result);
    }

    private List<Object> construct(String data) {
        return construct(new Constructor(), data);
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.