SnakeYAML implicitly converts time into integer

Issue #454 invalid
Evgeniy Stroykov created an issue

Hello, thank you for SnakeYAML!

Will start with code illustrating the issue:

import org.yaml.snakeyaml.Yaml;

import java.util.Map;

public class ImplicitTypes {
    private final static String input = "foo: 17:00:00";

    public static void main(String[] args) {
        final Yaml yaml = new Yaml();

        final Map<String, Object> map = yaml.load(input);

        // expected: 17:00:00
        // actual:   61200
        System.out.println(map.get("foo"));
    }
}
  1. YAML input foo: 17:00:00 is valid (checked it via an online validator) but parsed YAML contains number 61200 instead of string 17:00:00 (actually 61200 is 17 hours in seconds, i. e. 17 × 60 × 60).
  2. I’ve read about implicit types in documentation and I found that it is Tag.INT implicit resolver who makes this kind of transformation.
  3. I would say that this kind of transformation (17:00:00 → 61200) looks weird a little. Was it intended or this issue should be treated like a bug?

I use SnakeYaml 1.24 and JDK 12.

Comments (4)

  1. Andrey Somov

    This is a part of the specification.

    You can disable the transformation by providing your own Resolver.

    (search test for “extends Resolver“). You can define your pattern by removing the part which treats 17:00:00 specially.

    I will try to add an example later.

  2. Evgeniy Stroykov reporter

    Oh, this is a part of the specification! Now I see. Thank you for your explanation and your peace of advice! Issue may be closed.

  3. Log in to comment