Package org.yaml.snakeyaml

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


    public void testLoadWrongList() {
        String output = Util.getLocalResource("examples/list-bean-1.yaml");
        // System.out.println(output);
        Yaml beanLoader = new Yaml();
        try {
            beanLoader.loadAs(output, ListBean.class);
            fail("Global tags are required since Human is an interface.");
        } catch (Exception e) {
            assertTrue(e.getMessage(), e.getMessage().contains("Cannot create property=developers"));
        }
    }
View Full Code Here


    public void testLoadList() {
        String output = Util.getLocalResource("examples/list-bean-2.yaml");
        // System.out.println(output);
        Yaml beanLoader = new Yaml();
        ListBean parsed = beanLoader.loadAs(output, ListBean.class);
        assertNotNull(parsed);
        List<String> list2 = parsed.getChildren();
        assertEquals(2, list2.size());
        assertEquals("aaa", list2.get(0));
        assertEquals("bbb", list2.get(1));
View Full Code Here

    public void testLoadMap() {
        String output = Util.getLocalResource("examples/map-bean-1.yaml");
        // System.out.println(output);
        Yaml beanLoader = new Yaml();
        MapBean parsed = beanLoader.loadAs(output, MapBean.class);
        assertNotNull(parsed);
        SortedMap<String, String> sortedMap = parsed.getSorted();
        assertEquals(2, sortedMap.size());
        assertEquals("one", sortedMap.get("1"));
        assertEquals("two", sortedMap.get("2"));
View Full Code Here

        return new TestSuite(StressEmitterTest.class);
    }

    public void testPerformance() {
        Yaml loader = new Yaml();
        Invoice invoice = loader.loadAs(Util.getLocalResource("specification/example2_27.yaml"),
                Invoice.class);
        Yaml dumper = new Yaml();
        long time1 = System.nanoTime();
        dumper.dumpAsMap(invoice);
        long time2 = System.nanoTime();
View Full Code Here

            System.out.println("Started: " + id);
            Yaml loader = new Yaml();
            long time1 = System.nanoTime();
            int cycles = 200;
            for (int i = 0; i < cycles; i++) {
                Invoice invoice = loader.loadAs(doc, Invoice.class);
                assertNotNull(invoice);
            }
            long time2 = System.nanoTime();
            float duration = ((time2 - time1) / 1000000) / (float) cycles;
            System.out.println("Duration of " + id + " was " + duration + " ms/load.");
View Full Code Here

        float duration = (time2 - time1) / 1000000;
        System.out.println("Init was " + duration + " ms.");

        Yaml loader = new Yaml();
        time1 = System.nanoTime();
        loader.loadAs(doc, Invoice.class);
        time2 = System.nanoTime();
        duration = (time2 - time1) / 1000000;
        System.out.println("\nSingle load was " + duration + " ms.");

        loader = new Yaml();
View Full Code Here

        int[] range = new int[] { 1000, 2000 /* , 4000, 8000 */};
        System.out.println("\nOne instance.");
        for (int number : range) {
            time1 = System.nanoTime();
            for (int i = 0; i < number; i++) {
                loader.loadAs(doc, Invoice.class);
            }
            time2 = System.nanoTime();
            duration = ((time2 - time1) / 1000000) / (float) number;
            System.out.println("Duration for r=" + number + " was " + duration + " ms/load.");
            // cobertura may make it very slow
View Full Code Here

        System.out.println("\nMany instances.");
        for (int number : range) {
            time1 = System.nanoTime();
            for (int i = 0; i < number; i++) {
                loader = new Yaml();
                loader.loadAs(doc, Invoice.class);
            }
            time2 = System.nanoTime();
            duration = ((time2 - time1) / 1000000) / (float) number;
            System.out.println("Duration for r=" + number + " was " + duration + " ms/load.");
            // cobertura may make it very slow
View Full Code Here

    }

    @Test
    public void testJavaBeanLoader() throws IOException {
        Yaml yamlParser = new Yaml();
        MyCompositeObject obj = yamlParser.loadAs(getInput(), MyCompositeObject.class);
        check(obj);
    }

    private void check(MyCompositeObject obj) {
        Object[] values = { 1, "two", 3, "four", "!!!" };
View Full Code Here

        CollectionList bean = new CollectionList();
        Yaml yaml = new Yaml();
        String doc = yaml.dumpAsMap(bean);
        // System.out.println(doc);
        Yaml beanLoader = new Yaml();
        CollectionList parsed = beanLoader.loadAs(doc, CollectionList.class);
        assertTrue(parsed.getNames().contains("aaa"));
        assertTrue(parsed.getNames().contains("bbb"));
        assertEquals(2, parsed.getNames().size());
    }
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.