Package org.yaml.snakeyaml.nodes

Examples of org.yaml.snakeyaml.nodes.Tag


        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);
View Full Code Here


    // the tag must start with a digit
    @SuppressWarnings("unchecked")
    public void testImplicitResolver() {
        Yaml yaml = new Yaml(new DiceConstructor(), new DiceRepresenter());
        // the tag must start with a digit
        yaml.addImplicitResolver(new Tag("!dice"), Pattern.compile("\\d+d\\d+"), "123456789");
        // dump
        Map<String, Dice> treasure = (Map<String, Dice>) new HashMap<String, Dice>();
        treasure.put("treasure", new Dice(10, 20));
        String output = yaml.dump(treasure);
        assertEquals("{treasure: 10d20}\n", output);
View Full Code Here

    // the tag may start with anything
    @SuppressWarnings("unchecked")
    public void testImplicitResolverWithNull() {
        Yaml yaml = new Yaml(new DiceConstructor(), new DiceRepresenter());
        // the tag may start with anything
        yaml.addImplicitResolver(new Tag("!dice"), Pattern.compile("\\d+d\\d+"), null);
        // dump
        Map<String, Dice> treasure = (Map<String, Dice>) new HashMap<String, Dice>();
        treasure.put("treasure", new Dice(10, 20));
        String output = yaml.dump(treasure);
        assertEquals("{treasure: 10d20}\n", output);
View Full Code Here

        private class RepresentDice implements Represent {
            public Node representData(Object data) {
                Dice dice = (Dice) data;
                String value = dice.getA() + "d" + dice.getB();
                return representScalar(new Tag("!dice"), value);
            }
View Full Code Here

        }
    }

    class DiceConstructor extends SafeConstructor {
        public DiceConstructor() {
            this.yamlConstructors.put(new Tag("!dice"), new ConstructDice());
        }
View Full Code Here

        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
        Constructor constr = new Constructor();
        TypeDescription description = new TypeDescription(Wrapper.class, new Tag("!mybean"));
        constr.addTypeDescription(description);
        yaml = new Yaml(constr);
        Wrapper wrapper = (Wrapper) yaml.load(output);
        JavaBeanWithStaticState bean2 = wrapper.createBean();
        assertEquals(-47, bean2.getAge());
View Full Code Here

    public void testSerializerIsClosed2() throws IOException {
        serializer.open();
        serializer.close();
        try {
            serializer.serialize(new ScalarNode(new Tag("!foo"), "bar", null, null, (char) 0));
            fail();
        } catch (RuntimeException e) {
            assertEquals("serializer is closed", e.getMessage());
        }
    }
View Full Code Here

        }
    }

    public void testSerializerIsNotOpened2() throws IOException {
        try {
            serializer.serialize(new ScalarNode(new Tag("!foo"), "bar", null, null, (char) 0));
            fail();
        } catch (RuntimeException e) {
            assertEquals("serializer is not opened", e.getMessage());
        }
    }
View Full Code Here

            this.representers.put(java.sql.Timestamp.class, new RepresentTime());
        }

        private class RepresentFloat implements Represent {
            public Node representData(Object data) {
                return representScalar(new Tag(Tag.PREFIX + "java.lang.Float"),
                        ((Float) data).toString());
            }
View Full Code Here

            }
        }

        private class RepresentLong implements Represent {
            public Node representData(Object data) {
                return representScalar(new Tag(Tag.PREFIX + "java.lang.Long"),
                        ((Long) data).toString());
            }
View Full Code Here

TOP

Related Classes of org.yaml.snakeyaml.nodes.Tag

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.