Package org.yaml.snakeyaml.representer

Examples of org.yaml.snakeyaml.representer.Representer


                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


        DumperOptions.LineBreak lb = DumperOptions.LineBreak.UNIX;
        assertEquals("Line break: UNIX", lb.toString());
    }

    public void testWithRepresenter() {
        Representer representer = new Representer();
        DumperOptions options = new DumperOptions();
        options.setIndent(4);
        options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
        Yaml yaml = new Yaml(representer, options);
        List<Integer> list = new ArrayList<Integer>();
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

        assertSame(yaml1.constructor.getPropertyUtils(), yaml1.representer.getPropertyUtils());

        Yaml yaml2 = new Yaml(new Constructor());
        assertSame(yaml2.constructor.getPropertyUtils(), yaml2.representer.getPropertyUtils());

        Yaml yaml3 = new Yaml(new Representer());
        assertSame(yaml3.constructor.getPropertyUtils(), yaml3.representer.getPropertyUtils());
    }
View Full Code Here

        assertSame(pu, yaml.constructor.getPropertyUtils());
        assertSame(pu, yaml.representer.getPropertyUtils());
    }

    public void testYamlRepresenterWithPropertyUtils() {
        Representer representer2 = new Representer();
        PropertyUtils pu = new PropertyUtils();
        representer2.setPropertyUtils(pu);
        Yaml yaml = new Yaml(representer2);
        assertSame(pu, yaml.constructor.getPropertyUtils());
        assertSame(pu, yaml.representer.getPropertyUtils());
    }
View Full Code Here

    @Test
    public void testYamlConstructorANDRepresenterWithPropertyUtils() {
        Constructor constructor = new Constructor();
        PropertyUtils pu_c = new PropertyUtils();
        constructor.setPropertyUtils(pu_c);
        Representer representer = new Representer();
        PropertyUtils pu_r = new PropertyUtils();
        representer.setPropertyUtils(pu_r);
        Yaml yaml = new Yaml(constructor, representer);
        assertSame(pu_c, yaml.constructor.getPropertyUtils());
        assertSame(pu_r, yaml.representer.getPropertyUtils());
    }
View Full Code Here

        }
    }

    public void testDumpObjectNullOptions() {
        try {
            new JavaBeanDumper(new Representer(), null);
            fail();
        } catch (NullPointerException e) {
            assertEquals("DumperOptions must be provided.", e.getMessage());
        }
    }
View Full Code Here

    public void testEmitWithTags() {
        TestObject result = parseObject(Util.getLocalResource("ruby/ruby1.yaml"));
        DumperOptions options = new DumperOptions();
        options.setExplicitStart(true);
        Representer repr = new Representer();
        repr.addClassTag(TestObject.class, new Tag("!ruby/object:Test::Module::Object"));
        repr.addClassTag(Sub1.class, new Tag("!ruby/object:Test::Module::Sub1"));
        repr.addClassTag(Sub2.class, new Tag("!ruby/object:Test::Module::Sub2"));
        Yaml yaml2 = new Yaml(repr, options);
        String output = yaml2.dump(result);
        // System.out.println(output);
        assertTrue("Tags must be present.",
                output.startsWith("--- !ruby/object:Test::Module::Object"));
View Full Code Here

    public void testEmitWithTags2WithoutTagForParentJavabean() {
        TestObject result = parseObject(Util.getLocalResource("ruby/ruby1.yaml"));
        DumperOptions options = new DumperOptions();
        options.setExplicitStart(true);
        Representer repr = new Representer();
        repr.addClassTag(Sub1.class, new Tag("!ruby/object:Test::Module::Sub1"));
        repr.addClassTag(Sub2.class, new Tag("!ruby/object:Test::Module::Sub2"));
        Yaml yaml2 = new Yaml(repr, options);
        String output = yaml2.dump(result);
        // System.out.println(output);
        assertTrue("Tags must be present.",
                output.startsWith("--- !!org.yaml.snakeyaml.ruby.TestObject"));
View Full Code Here

      return value;
   }

   protected List<?> loadYamlData(final Reader io) throws IOException {
      final Yaml yaml = new Yaml(new Constructor(), new Representer(),
            new DumperOptions(), new YamlParserResolver());
      final Object loadedYaml = yaml.load(io);

      if (loadedYaml instanceof ArrayList) {
         return (ArrayList<?>) loadedYaml;
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.