Package org.yaml.snakeyaml.constructor

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


        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());
View Full Code Here


    }

    public void testMain() {
        Map<String, String> config = new HashMap<String, String>();
        config.put("user.home", "HOME");
        Constructor constructor = new ConfigurationConstructor(config);
        constructor.addTypeDescription(new TypeDescription(TestBean.class, "!testbean"));
        Yaml yaml = new Yaml(constructor);
        yaml.addImplicitResolver(CFG, Pattern.compile("\\$\\([a-zA-Z\\d\\u002E\\u005F]+\\)"), "$");
        TestBean bean = (TestBean) yaml.load("!testbean {myval: !cfg $(user.home)}");
        // System.out.println(bean.toString());
        assertEquals("Explicit tag must be respected", "HOME", bean.getMyval());
View Full Code Here

        Yaml yaml = new Yaml();
        String output = yaml.dumpAsMap(bean3);
        assertEquals("bean:\n  id: 3\n  name: Test me.\nlist: null\nname: Name123\n", output);
        TypeDescription td = new TypeDescription(Bean3.class);
        td.putListPropertyType("list", Integer.class);
        Yaml loader = new Yaml(new Constructor(td));
        Bean3 parsed = (Bean3) loader.load(output);
        assertEquals("Name123", parsed.getName());
    }
View Full Code Here

        Yaml yaml = new Yaml();
        String output = yaml.dumpAsMap(bean3);
        assertEquals("bean:\n  id: 3\n  name: Test me.\nlist:\n- 13\n- 17\nname: Name123\n", output);
        TypeDescription td = new TypeDescription(Bean3.class);
        td.putListPropertyType("list", Integer.class);
        Yaml loader = new Yaml(new Constructor(td));
        Bean3 parsed = (Bean3) loader.load(output);
        assertEquals("Name123", parsed.getName());
        List<Integer> parsedList = parsed.getList();
        assertEquals(2, parsedList.size());
    }
View Full Code Here

        bean3.setBean(bean);
        Yaml yaml = new Yaml();
        String output = yaml.dumpAsMap(bean3);
        assertEquals("bean:\n  id: 3\n  name: Test me.\nlist: null\nname: Name123\n", output);
        TypeDescription td = new TypeDescription(Bean2.class);
        Yaml loader = new Yaml(new Constructor(td));
        Bean3 parsed = loader.loadAs(output, Bean3.class);// Bean3 must be taken
        assertEquals("Name123", parsed.getName());
    }
View Full Code Here

        // System.out.println(output);
        String etalon = Util.getLocalResource("recursive/with-children.yaml");
        assertEquals(etalon, output);
        TypeDescription humanDescription = new TypeDescription(Human.class);
        humanDescription.putMapPropertyType("children", Human.class, Object.class);
        Yaml beanLoader = new Yaml(new Constructor(humanDescription));
        //
        Human son2 = beanLoader.loadAs(output, Human.class);
        assertNotNull(son2);
        assertEquals("Son", son.getName());
View Full Code Here

        // System.out.println(output);
        String etalon = Util.getLocalResource("recursive/with-children-pretty.yaml");
        assertEquals(etalon, output);
        TypeDescription humanDescription = new TypeDescription(Human.class);
        humanDescription.putMapPropertyType("children", Human.class, Object.class);
        Yaml beanLoader = new Yaml(new Constructor(humanDescription));
        //
        Human son2 = beanLoader.loadAs(output, Human.class);
        assertNotNull(son2);
        assertEquals("Son", son.getName());
View Full Code Here

        children.put(daughter, "daughter");
        father.setChildren(children);
        mother.setChildren(children);
        //

        Constructor constructor = new Constructor(Human2.class);
        TypeDescription humanDescription = new TypeDescription(Human2.class);
        humanDescription.putMapPropertyType("children", Human2.class, String.class);
        constructor.addTypeDescription(humanDescription);

        Yaml yaml = new Yaml(constructor);
        String output = yaml.dump(son);
        // System.out.println(output);
        String etalon = Util.getLocalResource("recursive/with-children-2.yaml");
View Full Code Here

        children.add(daughter);
        father.setChildren(children);
        mother.setChildren(children);
        //

        Constructor constructor = new Constructor(Human3.class);
        TypeDescription Human3Description = new TypeDescription(Human3.class);
        Human3Description.putListPropertyType("children", Human3.class);
        constructor.addTypeDescription(Human3Description);

        Yaml yaml = new Yaml(constructor);
        String output = yaml.dump(son);
        // System.out.println(output);
        String etalon = Util.getLocalResource("recursive/with-children-3.yaml");
View Full Code Here

     */
    @SuppressWarnings("unchecked")
    public void testChildrenSetAsRoot() {
        String etalon = Util.getLocalResource("recursive/with-children-as-set.yaml");

        Constructor constructor = new Constructor();
        TypeDescription humanDescription = new TypeDescription(Human.class);
        humanDescription.putMapPropertyType("children", Human.class, Object.class);
        constructor.addTypeDescription(humanDescription);

        Yaml yaml = new Yaml(constructor);
        Set<Human> children2 = (Set<Human>) yaml.load(etalon);
        assertNotNull(children2);
        assertEquals(2, children2.size());
View Full Code Here

TOP

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

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.