Examples of addImplicitResolver()


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

    private final Pattern CUSTOM_PATTERN = Pattern.compile("\\d+%");

    @SuppressWarnings("unchecked")
    public void testImplicit() {
        Yaml yaml = new Yaml(new BigConstructor());
        yaml.addImplicitResolver(CUSTOM_TAG, CUSTOM_PATTERN, "-0123456789");
        Map<String, Object> obj = (Map<String, Object>) yaml.load("bar: 50%");
        assertEquals("0.5", obj.get("bar").toString());
        assertEquals(BigDecimal.class, obj.get("bar").getClass());
    }
View Full Code Here

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

        assertEquals(BigDecimal.class, obj.get("bar").getClass());
    }

    public void testImplicitFailure() {
        Yaml yaml = new Yaml(new BigConstructor());
        yaml.addImplicitResolver(CUSTOM_TAG, Pattern.compile("\\d+%"), "-0123456789");
        try {
            yaml.load("bar: !!float 50%");
            fail("Both implicit and explicit are present.");
        } catch (NumberFormatException e) {
            assertEquals("For input string: \"50%\"", e.getMessage());
View Full Code Here

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

        assertEquals(4, ((Car) result).getWheels().size());
    }

    private Yaml yaml() {
        Yaml yaml = new Yaml(new MyConstructor());
        yaml.addImplicitResolver(new Tag("!wheel"), Pattern.compile("w#\\d+"), "w");
        return yaml;
    }

    @Test
    public void ignoreImplicitTag() {
View Full Code Here

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

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

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

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

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

    @SuppressWarnings("unchecked")
    public void testAddImplicitResolver() {
        Yaml yaml = new Yaml(new MyConstructor(), new MyRepresenter());
        Pattern regexp = Pattern.compile("\\d\\d-\\d\\d-\\d\\d\\d");
        yaml.addImplicitResolver(new Tag(Tag.PREFIX + "Phone"), regexp, "0123456789");
        Phone phone1 = new Phone("12-34-567");
        Phone phone2 = new Phone("11-22-333");
        Phone phone3 = new Phone("44-55-777");
        List<Phone> etalonList = new ArrayList<Phone>();
        etalonList.add(phone1);
View Full Code Here

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

    }

    public void testAddImplicitResolver2() {
        Yaml yaml = new Yaml(new PointRepresenter());
        Pattern regexp = Pattern.compile("\\d\\d-\\d\\d-\\d\\d\\d");
        yaml.addImplicitResolver(new Tag(Tag.PREFIX + "Phone"), regexp, "\0");
        Pattern regexp2 = Pattern.compile("x\\d_y\\d");
        // try any scalar, and not only those which start with 'x'
        yaml.addImplicitResolver(new Tag(Tag.PREFIX + "Point"), regexp2, null);
        Map<String, Object> map = new LinkedHashMap<String, Object>();
        map.put("a", new Phone("12-34-567"));
View Full Code Here

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

        Yaml yaml = new Yaml(new PointRepresenter());
        Pattern regexp = Pattern.compile("\\d\\d-\\d\\d-\\d\\d\\d");
        yaml.addImplicitResolver(new Tag(Tag.PREFIX + "Phone"), regexp, "\0");
        Pattern regexp2 = Pattern.compile("x\\d_y\\d");
        // try any scalar, and not only those which start with 'x'
        yaml.addImplicitResolver(new Tag(Tag.PREFIX + "Point"), regexp2, null);
        Map<String, Object> map = new LinkedHashMap<String, Object>();
        map.put("a", new Phone("12-34-567"));
        map.put("b", new Point(1, 5));
        String output = yaml.dump(map);
        assertEquals("{a: 12-34-567, b: x1_y5}\n", output);
View Full Code Here

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

        Map<String, String> config = new HashMap<String, String>();
        config.put("user.home", "HOME");
        Constructor constructor = new ConfigurationConstructor(config);
        constructor.addTypeDescription(new TypeDescription(TestBean.class, "!testbean"));
        Yaml yaml = new Yaml(constructor);
        yaml.addImplicitResolver(CFG, Pattern.compile("\\$\\([a-zA-Z\\d\\u002E\\u005F]+\\)"), "$");
        TestBean bean = (TestBean) yaml.load("!testbean {myval: !cfg $(user.home)}");
        // System.out.println(bean.toString());
        assertEquals("Explicit tag must be respected", "HOME", bean.getMyval());
        bean = (TestBean) yaml.load("!testbean {myval: $(user.home)}");
        // System.out.println(bean.toString());
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.