Package org.yaml.snakeyaml.representer

Examples of org.yaml.snakeyaml.representer.Representer


        assertEquals(1, w1.getId());
        //
        String carYaml1 = new Yaml().dump(car);
        assertTrue(carYaml1.startsWith("!!org.yaml.snakeyaml.constructor.Car"));
        //
        Representer representer = new Representer();
        representer.addClassTag(Car.class, new Tag("!car"));
        yaml = new Yaml(representer);
        String carYaml2 = yaml.dump(car);
        assertEquals(Util.getLocalResource("constructor/car-without-tags.yaml"), carYaml2);
    }
View Full Code Here


            wheels.put(mw, new Date(time + i));
        }
        MyCar c = new MyCar();
        c.setPlate("00-FF-Q2");
        c.setWheels(wheels);
        Representer representer = new Representer();
        representer.addClassTag(MyWheel.class, Tag.MAP);
        Yaml yaml = new Yaml(representer);
        String output = yaml.dump(c);
        assertEquals(Util.getLocalResource("javabeans/mycar-with-global-tag1.yaml"), output);
        // load
        Yaml beanLoader = new Yaml();
View Full Code Here

            Wheel wheel = new Wheel();
            wheel.setId(i);
            wheels.add(wheel);
        }
        car.setWheels(wheels);
        Representer representer = new Representer();
        representer.addClassTag(Car.class, new Tag("!car"));
        representer.addClassTag(Wheel.class, Tag.MAP);
        Yaml yaml = new Yaml(representer);
        String output = yaml.dump(car);
        assertEquals(Util.getLocalResource("constructor/car-without-tags.yaml"), output);
    }
View Full Code Here

        }
        DumperOptions options = new DumperOptions();
        options.setIndent(4);
        options.setDefaultFlowStyle(FlowStyle.AUTO);

        Representer representer = new Representer() {
            @Override protected Set<Property> getProperties(Class<? extends Object> type) throws IntrospectionException {
                Set<Property> properties = super.getProperties(type);
                Property parentProperty = null;
                for (Property property : properties) {
                    if (property.getName().equals("parent"))
View Full Code Here

     * A new method setSkipMissingProperties(boolean) was added to configure
     * whether missing properties should throw a YAMLException (the default) or
     * simply show a warning. The default is false.
     */
    public void testSkipMissingProperties() throws Exception {
        Representer representer = new Representer();
        representer.getPropertyUtils().setSkipMissingProperties(true);
        yaml = new Yaml(new Constructor(), representer);
        String doc = "goodbye: 10\nhello: 5\nfizz: [1]";
        TestBean bean = yaml.loadAs(doc, TestBean.class);
        assertNotNull(bean);
        assertEquals(5, bean.hello);
View Full Code Here

     * The default for setSkipMissingProperties(boolean) is false; this just
     * ensures it works if set manually.
     */
    public void testNoSkipMissingProperties() throws Exception {
        try {
            Representer representer = new Representer();
            representer.getPropertyUtils().setSkipMissingProperties(false);
            yaml = new Yaml(new Constructor(), representer);
            String doc = "goodbye: 10";
            yaml.loadAs(doc, TestBean.class);
        } catch (YAMLException e) {
            assertTrue(e.getMessage().contains("Cannot create property=goodbye"));
View Full Code Here

        children.put(son, "son");
        children.put(daughter, "daughter");
        father.setChildren(children);
        mother.setChildren(children);
        //
        Representer representer = new Representer();
        representer.addClassTag(HumanGen2.class, Tag.MAP);
        Yaml yaml = new Yaml(representer);
        String output = yaml.dump(son);
        // System.out.println(output);
        String etalon = Util.getLocalResource("recursive/generics/with-children-2.yaml");
        assertEquals(etalon, output);
View Full Code Here

        Blog rehydrated = (Blog) yaml.load(serialized);
        checkTestBlog(rehydrated);
    }

    protected Yaml constructYamlDumper() {
        Representer representer = new Representer();
        representer.getPropertyUtils().setBeanAccess(BeanAccess.FIELD);
        Yaml yaml = new Yaml(representer);
        return yaml;
    }
View Full Code Here

    public void save() throws IOException {
        FileWriter writer = new FileWriter(getConfigFile());
        DumperOptions options = new DumperOptions();
        options.setDefaultFlowStyle(FlowStyle.AUTO);
        options.setIndent(4);
        Representer representer = new Representer();
        representer.getPropertyUtils().setBeanAccess(BeanAccess.DEFAULT);
        new Yaml(options).dump(this, writer);
    }
View Full Code Here

        try {
            DumperOptions options = new DumperOptions();
            options.setIndent(4);
            options.setDefaultFlowStyle(FlowStyle.AUTO);

            Representer representer = new Representer() {
                @Override protected Set<Property> getProperties(Class<? extends Object> type) throws IntrospectionException {
                    Set<Property> properties = super.getProperties(type);
                    Property parentProperty = null;
                    for (Property property : properties) {
                        if (property.getName().equals("parent"))
View Full Code Here

TOP

Related Classes of org.yaml.snakeyaml.representer.Representer

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.