Package org.yaml.snakeyaml

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


    public void testAsStandalone() {
        ParameterizedBean<Integer, String> bean = new ParameterizedBean<Integer, String>();
        bean.setK(13);
        bean.setV("ID47");
        Yaml yaml = new Yaml();
        String result = yaml.dump(bean);
        assertEquals("!!org.yaml.snakeyaml.issues.issue115.ParameterizedBean {k: 13, v: ID47}\n",
                result);
        // load
        @SuppressWarnings("unchecked")
        ParameterizedBean<Integer, String> beanParsed = (ParameterizedBean<Integer, String>) yaml
View Full Code Here


        IssueBean issue = new IssueBean();
        ParameterizedBean<Integer, String> bean = new ParameterizedBean<Integer, String>();
        bean.setK(432);
        bean.setV("Val432");
        issue.setBean(bean);
        String result = yaml.dump(issue);
        assertEquals("!!org.yaml.snakeyaml.issues.issue115.IssueBean\nbean: {k: 432, v: Val432}\n",
                result);
        // load
        IssueBean issueParsed = (IssueBean) yaml.load(result);
        assertEquals(new Integer(432), issueParsed.getBean().getK());
View Full Code Here

        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);
    }

    public static class CarWithWheel {
        private String plate;
View Full Code Here

        assertEquals("public", result.publicField);
        //
        DumperOptions options = new DumperOptions();
        options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
        Yaml yamlToDump = new Yaml(options);
        String output = yamlToDump.dump(result);
        TestBean1 result2 = (TestBean1) yaml.load(output);
        assertNotNull(result2);
        TestBean1 result3 = (TestBean1) new Yaml().load(output);
        assertNotNull(result3);
    }
View Full Code Here

import org.yaml.snakeyaml.reader.ReaderException;

public class PrintableUnicodeTest extends TestCase {
    public void testFFFD() {
        Yaml yaml = createYaml();
        String fffd = yaml.dump("\uFFFD");
        assertEquals("\"\\ufffd\"\n", fffd);
    }

    public void testSerialization() {
        // test serialization of all Unicode codepoints
View Full Code Here

    public void testSerialization() {
        // test serialization of all Unicode codepoints
        Yaml yaml = createYaml();
        for (int c = Character.MIN_VALUE; c <= Character.MAX_VALUE; c++) {
            String original = Character.toString((char) c);
            String serialized = yaml.dump(original);

            // "On output, a YAML processor must only produce these acceptable
            // characters,
            // and should also escape all non-printable Unicode characters."
            for (int i = 0; i < serialized.length(); i++) {
View Full Code Here

        srcVector.add("is");
        srcVector.add("a");
        srcVector.add("test");
        // System.out.println("Source Vector: " + srcVector);
        Yaml yaml = new Yaml();
        String instance = yaml.dump(srcVector);
        // System.out.println("YAML String: " + new String(instance));
        yaml = new Yaml(new Constructor("java.util.Vector"));
        // If I try to get a Vector I receive a class cast exception.
        Vector<String> vector = (Vector<String>) yaml.load(new String(instance));
        // System.out.println("Vector: " + vector);
View Full Code Here

    public void testRepresentor() {
        IncompleteJavaBean bean = new IncompleteJavaBean();
        DumperOptions options = new DumperOptions();
        options.setAllowReadOnlyProperties(true);
        Yaml yaml = new Yaml(options);
        String output = yaml.dump(bean);
        String className = this.getClass().getPackage().getName();
        assertEquals("!!" + className + ".IncompleteJavaBean {name: No name}\n", output);
    }

    public void testConstructor() {
View Full Code Here

        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();
        MyCar car = beanLoader.loadAs(output, MyCar.class);
        assertNotNull(car);
View Full Code Here

    public void testDumpFlow() {
        DumperOptions options = new DumperOptions();
        options.setAllowReadOnlyProperties(true);
        Yaml yaml = new Yaml(new SetRepresenter(), options);
        String output = yaml.dump(createBlog());
        // System.out.println(output);
        assertEquals(Util.getLocalResource("issues/issue73-dump7.txt"), output);
        //
        check(output);
    }
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.