Package org.yaml.snakeyaml

Examples of org.yaml.snakeyaml.DumperOptions


public class SerializerTest extends TestCase {
    private Serializer serializer;

    @Override
    protected void setUp() {
        DumperOptions config = new DumperOptions();
        StringWriter writer = new StringWriter();
        serializer = new Serializer(new Emitter(writer, config), new Resolver(), config, null);
    }
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

    /**
     * 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

        assertTrue("No test files found.", files.length > 0);
        for (int i = 0; i < files.length; i++) {
            String content = getResource(files[i].getName());
            List<Event> document = (List<Event>) load(new EventConstructor(), content.trim());
            Writer writer = new StringWriter();
            Emitter emitter = new Emitter(writer, new DumperOptions());
            try {
                for (Event event : document) {
                    emitter.emit(event);
                }
                fail("Loading must fail for " + files[i].getAbsolutePath());
View Full Code Here

        mother.setBirthday(new Date(100000000000L));
        mother.setBirthPlace("Saint-Petersburg");
        father.setPartner(mother);
        mother.setPartner(father);
        mother.setBankAccountOwner(father);
        DumperOptions options = new DumperOptions();
        options.setPrettyFlow(true);
        options.setDefaultFlowStyle(FlowStyle.FLOW);
        Yaml yaml = new Yaml(options);
        String output = yaml.dump(father);
        String etalon = Util.getLocalResource("recursive/no-children-1-pretty.yaml");
        assertEquals(etalon, output);
        //
View Full Code Here

        children.add(son);
        children.add(daughter);
        father.setChildren(children);
        mother.setChildren(children);
        //
        DumperOptions options = new DumperOptions();
        options.setDefaultFlowStyle(FlowStyle.FLOW);
        options.setPrettyFlow(true);
        Yaml beanDumper = new Yaml(options);
        String output = beanDumper.dump(son);
        // System.out.println(output);
        String etalon = Util.getLocalResource("recursive/with-children-pretty.yaml");
        assertEquals(etalon, output);
View Full Code Here

        assertEquals(rect, loaded);
    }

    // matteborder - only with color - no icon
    public void testMatteBorder() {
        DumperOptions options = new DumperOptions();
        options.setWidth(400);
        Yaml yaml = new Yaml(new ImmutablesRepresenter(), options);
        Insets insets = new Insets(10, 20, 30, 40);
        Color color = new Color(100, 150, 200);
        MatteBorder border = BorderFactory.createMatteBorder(insets.top, insets.left,
                insets.bottom, insets.right, color);
View Full Code Here

                InputStream input = new FileInputStream(file);
                List<Event> events = parse(input);
                input.close();
                //
                StringWriter stream = new StringWriter();
                DumperOptions options = new DumperOptions();
                options.setCanonical(canonical);
                Emitter emitter = new Emitter(stream, options);
                for (Event event : events) {
                    emitter.emit(event);
                }
                //
View Full Code Here

        }
    }

    private String emit(List<Event> events) throws IOException {
        StringWriter writer = new StringWriter();
        Emitter emitter = new Emitter(writer, new DumperOptions());
        for (Event event : events) {
            emitter.emit(event);
        }
        return writer.toString();
    }
View Full Code Here

TOP

Related Classes of org.yaml.snakeyaml.DumperOptions

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.