Package org.yaml.snakeyaml.representer

Examples of org.yaml.snakeyaml.representer.Representer


    public void testDumpCustomTag() {
        Académico obj = new Académico();
        obj.setId(123);
        obj.setName("Foo bar 123");
        Representer repr = new Representer();
        repr.addClassTag(Académico.class, new Tag("!foo"));
        Yaml yaml = new Yaml(repr);
        String result = yaml.dump(obj);
        assertEquals("!foo {id: 123, name: Foo bar 123}\n", result);
    }
View Full Code Here


    public void testDumpEscapedTag() {
        Académico obj = new Académico();
        obj.setId(123);
        obj.setName("Foo bar 123");
        Representer repr = new Representer();
        repr.addClassTag(Académico.class, new Tag("!Académico"));
        Yaml yaml = new Yaml(repr);
        String result = yaml.dump(obj);
        assertEquals("!Acad%C3%A9mico {id: 123, name: Foo bar 123}\n", result);
    }
View Full Code Here

//issue 59
public class CustomOrderTest extends TestCase {

    public void testReversedOrder() {
        Representer repr = new Representer();
        repr.setPropertyUtils(new ReversedPropertyUtils());
        Yaml yaml = new Yaml(repr);
        String output = yaml.dump(getBean());
        // System.out.println(output);
        assertEquals(Util.getLocalResource("issues/issue59-1.yaml"), output);
    }
View Full Code Here

            return result;
        }
    }

    public void testUnsorted() {
        Representer repr = new Representer();
        repr.setPropertyUtils(new UnsortedPropertyUtils());
        Yaml yaml = new Yaml(repr);
        String output = yaml.dump(getBean());
        // System.out.println(output);
        assertEquals(Util.getLocalResource("issues/issue59-2.yaml"), output);
    }
View Full Code Here

    }

    public void testLongRepresenter() {
        DumperOptions options = new DumperOptions();
        options.setDefaultScalarStyle(DumperOptions.ScalarStyle.DOUBLE_QUOTED);
        Representer repr = new Representer();
        repr.addClassTag(Long.class, new Tag("!!java.lang.Long"));
        Yaml yaml = new Yaml(repr, options);

        Foo foo = new Foo();
        String output = yaml.dump(foo);
        // System.out.println(output);
View Full Code Here

        customerAB.aAll = all;
        customerAB.bGeneral = general;

        Constructor constructor = new Constructor();
        Representer representer = new Representer();
        Tag generalAccountTag = new Tag("!GA");
        constructor
                .addTypeDescription(new TypeDescription(GeneralAccount.class, generalAccountTag));
        representer.addClassTag(GeneralAccount.class, generalAccountTag);

        Yaml yaml = new Yaml(constructor, representer);
        String dump = yaml.dump(customerAB);
        // System.out.println(dump);
        CustomerAB parsed = (CustomerAB) yaml.load(dump);
View Full Code Here

        customerAB_property.acc = generalAccount;
        customerAB_property.bGeneral = general;

        Constructor constructor = new Constructor();
        Representer representer = new Representer();

        Yaml yaml = new Yaml(constructor, representer);
        String dump = yaml.dump(customerAB_property);
        // System.out.println(dump);
        CustomerAB_Property parsed = (CustomerAB_Property) yaml.load(dump);
View Full Code Here

        customerAB_property.acc = generalAccount;
        customerAB_property.bGeneral = general;

        Constructor constructor = new Constructor();
        Representer representer = new Representer();

        Tag generalAccountTag = new Tag("!GA");
        constructor
                .addTypeDescription(new TypeDescription(GeneralAccount.class, generalAccountTag));
        representer.addClassTag(GeneralAccount.class, generalAccountTag);

        Yaml yaml = new Yaml(constructor, representer);
        String dump = yaml.dump(customerAB_property);
        // System.out.println(dump);
        CustomerAB_Property parsed = (CustomerAB_Property) yaml.load(dump);
View Full Code Here

        JavaBeanWithStaticState bean = new JavaBeanWithStaticState();
        bean.setName("Bahrack");
        bean.setAge(-47);
        JavaBeanWithStaticState.setType("Type3");
        JavaBeanWithStaticState.color = "Violet";
        Representer repr = new Representer();
        repr.addClassTag(Wrapper.class, new Tag("!mybean"));
        Yaml yaml = new Yaml(repr);
        String output = yaml.dump(new Wrapper(bean));
        // System.out.println(output);
        assertEquals("!mybean {age: -47, color: Violet, name: Bahrack, type: Type3}\n", output);
        // parse back to instance
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

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.