SnakeYAML implicitly converts time into integer
Issue #454
invalid
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"));
}
}
- YAML input
foo: 17:00:00
is valid (checked it via an online validator) but parsed YAML contains number 61200 instead of string17:00:00
(actually 61200 is 17 hours in seconds, i. e. 17 × 60 × 60). - I’ve read about implicit types in documentation and I found that it is Tag.INT implicit resolver who makes this kind of transformation.
- 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)
-
-
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.
-
- changed status to invalid
See the example:
-
reporter Thank you!
- Log in to comment
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.