-
-
Notifications
You must be signed in to change notification settings - Fork 148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When field names are reserved words, they should be written out with quotes #68
Comments
Thank you for reporting this, contributing patch. Bit odd that SnakeYAML does not do escaping. But as with everything, looks like YAML has gone off the deep end with the rather long list of reserved names.... so maybe it's impractical. |
Thanks for the quick response! And yeah, YAML's actual spec is chaos: The content of a mapping node is an unordered set of key: value node pairs, with the restriction that
each of the keys is unique. YAML places no further restrictions on the nodes. In particular, keys may be
arbitrary nodes, the same node may be used as the value of several key: value pairs, and a mapping
could even contain itself as a key or a value (directly or indirectly). Given that, the minimal-change way to support reserved-words keys without actually implementing the full YAML spec in Jackson's/SnakeYAML's writer is adding a feature to just quote all keys. But hey, I'll ask you one favor: would you able to backport this to jackson-dataformat-yaml 2.7.x? |
@baconmania Wrt 2.7, unfortunately no. If I followed semantic versioning strictly, this could even go in 2.9 being new feature. But since that branch is open and likely the last 2.x version I don't have problem doing that. However backporting is different story -- 2.7 in particular is closed and only "micro-patches" are to be release (like 2.7.9.1) for critical bugs. Thank you for feature PR itself; I'll add just one note there. |
@baconmania I actually decided to try to add only-if-needed quoting, and not yet adding new feature to force quoting. Happy to add such feature if it's needed of course. Will finally be in 2.9.9 and 2.10.0. |
https://github.com/FasterXML/jackson-dataformat-yaml/blob/master/src/main/java/com/fasterxml/jackson/dataformat/yaml/YAMLGenerator.java specifies that YAML keys will always be written with
STYLE_NAME
, e.g. without quotes.But this breaks parsers when you write a map with a key that is a reserved word in YAML, e.g.
no
. If_writeFieldName()
encounters a field that is one of{ y, true, yes, on, n, false, no, off }
, it should useSTYLE_QUOTED
.Actual definition of such boolean values can be found here:
https://yaml.org/type/bool.html
The text was updated successfully, but these errors were encountered: