Package org.yaml.snakeyaml.constructor

Examples of org.yaml.snakeyaml.constructor.Constructor$ConstructSequence


    public void testLoadList2() {
        String output = Util.getLocalResource("examples/list-bean-3.yaml");
        // System.out.println(output);
        TypeDescription descr = new TypeDescription(ListBean.class);
        descr.putListPropertyType("developers", Developer.class);
        Yaml beanLoader = new Yaml(new Constructor(descr));
        ListBean parsed = beanLoader.loadAs(output, ListBean.class);
        assertNotNull(parsed);
        List<Human> developers = parsed.getDevelopers();
        assertEquals(2, developers.size());
        assertEquals("Committer must be recognised.", Developer.class, developers.get(0).getClass());
View Full Code Here


        assertEquals(174, bean.getId());
        assertEquals(map, bean.getMap());
    }

    public void testLoadEnumBean2() {
        Constructor c = new Constructor();
        TypeDescription td = new TypeDescription(EnumBean.class);
        td.putMapPropertyType("map", Suit.class, Object.class);
        c.addTypeDescription(td);
        Yaml yaml = new Yaml(c);
        EnumBean bean = (EnumBean) yaml
                .load("!!org.yaml.snakeyaml.EnumBean\nid: 174\nmap:\n  CLUBS: 1\n  DIAMONDS: 2\nsuit: CLUBS");

        LinkedHashMap<Suit, Integer> map = new LinkedHashMap<Suit, Integer>();
View Full Code Here

    public YamlDocument(String sourceName, boolean check, Constructor constructor) {
        InputStream input = YamlDocument.class.getClassLoader().getResourceAsStream(
                ROOT + sourceName);
        if (constructor == null) {
            constructor = new Constructor();
        }
        Yaml yaml = new Yaml(constructor);
        nativeData = yaml.load(input);
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        Charset charset = Charset.forName("UTF-8");
View Full Code Here

            // System.out.println(c);
        }
    }

    public void test11withoutPackageNames() {
        Constructor compact = new PackageCompactConstructor(
                "org.yaml.snakeyaml.extensions.compactnotation");
        Yaml yaml = new Yaml(compact);
        String doc = Util.getLocalResource("compactnotation/example11.yaml");
        Box box = (Box) yaml.load(doc);
        assertNotNull(box);
View Full Code Here

        assertEquals("3.5", bottom.getPrice());
        assertEquals("sweet", bottom.getName());
    }

    public void test12withList() {
        Constructor compact = new TableCompactConstructor(
                "org.yaml.snakeyaml.extensions.compactnotation");
        Yaml yaml = new Yaml(compact);
        String doc = Util.getLocalResource("compactnotation/example12.yaml");
        Table table = (Table) yaml.load(doc);
        assertNotNull(table);
View Full Code Here

public class CustomResolverTest extends TestCase {

    public void testResolverToDump() {
        Map<Object, Object> map = new HashMap<Object, Object>();
        map.put("1.0", "2009-01-01");
        Yaml yaml = new Yaml(new Constructor(), new Representer(), new DumperOptions(),
                new CustomResolver());
        String output = yaml.dump(map);
        assertEquals("{1.0: 2009-01-01}\n", output);
        assertEquals("Float and Date must be escaped.", "{'1.0': '2009-01-01'}\n",
                new Yaml().dump(map));
View Full Code Here

                new Yaml().dump(map));
    }

    @SuppressWarnings("unchecked")
    public void testResolverToLoad() {
        Yaml yaml = new Yaml(new Constructor(), new Representer(), new DumperOptions(),
                new CustomResolver());
        Map<Object, Object> map = (Map<Object, Object>) yaml.load("1.0: 2009-01-01");
        assertEquals(1, map.size());
        assertEquals("2009-01-01", map.get("1.0"));
        // the default Resolver shall create Date and Double from the same YAML
View Full Code Here

* @see http://yaml.org/spec/1.1/
*/
public class Example2_27Test extends TestCase {

    public void testExample_2_27() {
        Yaml yaml = new Yaml(new Constructor(Invoice.class));
        Invoice invoice = (Invoice) yaml.load(Util
                .getLocalResource("specification/example2_27.yaml"));
        assertNotNull(invoice);
        Person billTo = invoice.billTo;
        assertEquals("Dumars", billTo.family);
View Full Code Here

        doc = Util.getLocalResource("specification/example2_27.yaml");
    }

    public void testPerformance() {
        long time1 = System.nanoTime();
        new Yaml(new Constructor(Invoice.class));
        long time2 = System.nanoTime();
        float duration = (time2 - time1) / 1000000;
        System.out.println("Init was " + duration + " ms.");

        Yaml loader = new Yaml();
View Full Code Here

    /**
     * Parse scalars as Strings
     */
    @SuppressWarnings({ "unchecked", "deprecation" })
    public void testStringResolver() {
        Yaml yaml = new Yaml(new Constructor(), new Representer(), new DumperOptions(),
                new Resolver(false));
        List<Object> output = (List<Object>) yaml.load("[ '1.00', 1.00, !!float '1.00' ]");
        assertEquals("1.00", output.get(0));
        assertEquals("1.00", output.get(1));
        assertEquals(1.0, output.get(2));
View Full Code Here

TOP

Related Classes of org.yaml.snakeyaml.constructor.Constructor$ConstructSequence

Copyright © 2018 www.massapicom. 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.