yeison / snakeyaml

Automatically exported from code.google.com/p/snakeyaml
Apache License 2.0
0 stars 0 forks source link

value resolves to FLOAT inspite of being INT #190

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.load yaml with sample input "tag: 0000012345\n"
2.
3.

What is the expected output? What do you see instead?
expected output tag:12345 actual output tag:12345.0

What version of SnakeYAML are you using? On what Java version?
1.11 on java 1.6.0_65 macosx

Please provide any additional information below. (Often a failing test is
the best way to describe the problem.)
It is expected to hit INT since the implict resolver has a regex matching INT 
before the FLOAT. However it is being considered FLOAT.

Original issue reported on code.google.com by spotha...@gmail.com on 23 Apr 2014 at 12:49

GoogleCodeExporter commented 9 years ago
According to the spec (http://yaml.org/type/int.html) if a number starts with 0 
it is considered to be octal.
I tried both version 1.11 and the latest version, everywhere it works properly.
You can try it:
 public void testIntInMap() throws Exception {
        Yaml yaml = new Yaml();
        String doc = "tag: 0000012345\n";
        Map<String, Integer> map = (Map<String, Integer>) yaml.load(doc);
        int n = map.get("tag").intValue();
        assertEquals(5349, n);
    }

I am afraid there a problem somewhere in your code.

Please provide a failing test to prove the unexpected conversion from INT to 
FLOAT.

Original comment by py4fun@gmail.com on 23 Apr 2014 at 7:29

GoogleCodeExporter commented 9 years ago
Sorry this is not an issue. you are right it correctly converted all strings 
with leading 0 to octals.

Original comment by spotha...@gmail.com on 24 Apr 2014 at 7:10

GoogleCodeExporter commented 9 years ago

Original comment by py4fun@gmail.com on 24 Apr 2014 at 7:12