Re: Quoting strings of digits
Laurent Lyaudet <[email protected]> Mon, 20 Nov 2017 20:15:50 +0100
| Newsgroups | gmane.text.yaml.general |
|---|---|
| Message-ID | <CAB1LBmv4pXJ5qDm=g6=mEFpPrd=KtsGYRLa1GNwYcPG+Y87uwg@mail.gmail.com> |
Hi Thomas, In my humble opinion, I think the problem is on the Java side. If I quote the spec for YAML 1.2 : "Decimal integer notation, with a leading “-” character for negative values, matching the regular expression 0 | -? [1-9] [0-9]*" As you can see, there is no leading zero tolerated for integers except for the value 0. Hence 08063075 is a valid string element, pyyaml can strip the quotes and snakeyaml should understand that. Best regards, Laurent Lyaudet 2017-11-20 2:10 GMT+01:00 Thomas Conway <[email protected]>: > Hi Yamlies, > > I have a bit of a problem where some of our tools use Java, and some Python > (2). The output of the python is consumed by the Java, and inconsistencies > are leading to some problems. My question is which if any behaviours are > incorrect with respect to the specification? > > I've cut down the problem to the following. > > Consider the following python code (using pyyaml): > > import sys > import yaml > w = {'userName': 'scientist ', 'userEmail': '[email protected]', > 'sampleName': '08063075', 'fastqDir': > '/foo/bar/baz/171108_M00139_0253_000000000-BHFD5/ProjectFolders/Project_Qux-Wombat-/Sample_08063075', > 'analysis': 'Somatic_Run375_MY_DY_08112017', 'laneNo': 1, 'panel': > 'Somatic_Panel_Manifest_v4_23_10_2015'} > yaml.dump(w, sys.stdout, default_flow_style=False) > > which produces the output: > > analysis: Somatic_Run375_MY_DY_08112017 > fastqDir: > /foo/bar/baz/171108_M00139_0253_000000000-BHFD5/ProjectFolders/Project_Qux-Wombat-/Sample_08063075 > laneNo: 1 > panel: Somatic_Panel_Manifest_v4_23_10_2015 > sampleName: 08063075 > userEmail: [email protected] > userName: 'scientist ' > > Note in particular that the string value for the key 'sampleName' is a > sequence of digits with a leading zero, and is not quoted. > > When we read it in to our java system (using snakeyaml), the unquoted > sequence of digits is turned into an integer, which means that subsequent > steps drop the leading zero. > > I've tried reading the specification, but I can't see that it defines the > conversion. > > Is the serialisation valid? > > Is the conversion of the string of digits to an integer valid? > > Thanks for any precision you can add to my understanding, > > Tom. > -- > Dr Thomas Conway > [email protected] > My friends, love is better than anger. Hope is better than fear. Optimism is > better than despair. So let us be loving, hopeful and optimistic. And we'll > change the world. - Jack Layton > > ------------------------------------------------------------------------------ > Check out the vibrant tech community on one of the world's most > engaging tech sites, Slashdot.org! http://sdm.link/slashdot > _______________________________________________ > Yaml-core mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/yaml-core > ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ Yaml-core mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/yaml-core