SnakeYaml does not conform to specification on Boolean (!!bool) data type.

619 views
Skip to first unread message

DemonWasp

unread,
Jan 31, 2011, 5:06:15 PM1/31/11
to SnakeYAML
For reference: http://yaml.org/type/bool.html

The specification clearly states that the strings 'n', 'N', 'y' and
'Y' are to be resolved as booleans and accepted as booleans, and that
the canonical format of a boolean is either 'y' or 'n'. SnakeYaml does
not resolve these values to !!bool, and if the value is explicitly
tagged !!bool, then it will emit an error (incorrectly).

For example, the following is a valid YAML 1.1 document:
---
awesome: !!bool y
...
but SnakeYaml disagrees, giving the message "The document is not valid
YAML".


I don't know whether the specification _should_ be followed in this
case. The reason it shouldn't be followed is that it is reasonable to
expect that a lot of Java objects will have coordinate parameters
(x,y,z), and that the 'y' coordinate key node would then implicitly
resolve to !!bool, despite the document looking like a set of
coordinate values.

On the other hand, SnakeYaml already has workarounds in place to allow
implicitly-resolved integers (123) to be used as property names
(set123, get123), so it's possible that a workaround would be the best
choice here too.

Andrey

unread,
Feb 1, 2011, 3:56:26 AM2/1/11
to snakeya...@googlegroups.com
Hi,
it used to be implemented as in the spec but it was changed (http://code.google.com/p/snakeyaml/source/detail?r=144a54d0f7f387e0077d9181e81684a93d71fc50) due to the following:

1) the spec is a bit inconsistent here. Check example 2.24 in the spec (http://yaml.org/spec/1.1/). It clearly show that 'x' and 'y' are expected to be just names
2) it may be confusing in many contexts
3) I asked the very same question PyYAML developers and I got a similar answer. SnakeYAML tries to keep strong interoperability with other languages. The same engine is used now in Python (PyYAML), Ruby (Psych), Java (SnakeYAML). It allows to easily exchange documents between languages
4) In the coming 1.2 specification a lot of values for boolean are dropped - http://www.yaml.org/spec/1.2/spec.html#id2803629
If no one is using 'y' and 'x' now as booleans then there will be no problems later with the 1.2 specification

I hope I have answered the question.
Andrey

maslovalex

unread,
Feb 1, 2011, 4:01:43 AM2/1/11
to SnakeYAML
btw. maybe we it is the one for
http://code.google.com/p/snakeyaml/wiki/Documentation#Deviations_from_the_specification
, it it?

-alex

On Feb 1, 10:56 am, Andrey <py4...@gmail.com> wrote:
> Hi,
> it used to be implemented as in the spec but it was changed (http://code.google.com/p/snakeyaml/source/detail?r=144a54d0f7f387e007...)
> due to the following:
>
> 1) the spec is a bit inconsistent here. Check example 2.24 in the spec
> (http://yaml.org/spec/1.1/). It clearly show that 'x' and 'y' are expected
> to be just names
> 2) it may be confusing in many contexts
> 3) I asked the very same question PyYAML developers and I got a similar
> answer. SnakeYAML tries to keep strong interoperability with other
> languages. The same engine is used now in Python (PyYAML), Ruby (Psych),
> Java (SnakeYAML). It allows to easily exchange documents between languages
> 4) In the coming 1.2 specification a lot of values for boolean are dropped
> -http://www.yaml.org/spec/1.2/spec.html#id2803629

Andrey

unread,
Feb 1, 2011, 4:12:37 AM2/1/11
to snakeya...@googlegroups.com

DemonWasp

unread,
Feb 1, 2011, 8:00:43 AM2/1/11
to SnakeYAML
I'm starting to see that the spec is more than a little inconsistent.
This is the answer I was expecting, thanks.

/Jordan


On Feb 1, 3:56 am, Andrey <py4...@gmail.com> wrote:
> Hi,
> it used to be implemented as in the spec but it was changed (http://code.google.com/p/snakeyaml/source/detail?r=144a54d0f7f387e007...)
> due to the following:
>
> 1) the spec is a bit inconsistent here. Check example 2.24 in the spec
> (http://yaml.org/spec/1.1/). It clearly show that 'x' and 'y' are expected
> to be just names
> 2) it may be confusing in many contexts
> 3) I asked the very same question PyYAML developers and I got a similar
> answer. SnakeYAML tries to keep strong interoperability with other
> languages. The same engine is used now in Python (PyYAML), Ruby (Psych),
> Java (SnakeYAML). It allows to easily exchange documents between languages
> 4) In the coming 1.2 specification a lot of values for boolean are dropped
> -http://www.yaml.org/spec/1.2/spec.html#id2803629
Reply all
Reply to author
Forward
0 new messages