Skip to content
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

YAMLGenerator: String unnecessarily quoted with MINIMIZE_QUOTES enabled #230

Open
bjpe opened this issue Nov 5, 2020 · 2 comments
Open
Labels
yaml Issue related to YAML format backend

Comments

@bjpe
Copy link

bjpe commented Nov 5, 2020

Hi, moving from Jackson 2.10.3 to 2.11.3 we discovered that the YAMLGenerator now has a different behaviour when serializing strings that contain special charaters like {, }, [, ], ,. I suspect that this is due to #180. This issue references the YAML spec (https://yaml.org/spec/1.2/spec.html#id2788859), which says

In addition, inside flow collections, or when used as implicit keys, plain scalars must not contain the “[”, “]”, “{”, “}” and “,” characters. These characters would cause ambiguity with flow collection structures.

However, the spec says that quoting of strings containing the above mentioned characters is only necessary in flow collections, but not outside.

Are there flags controlling the output of collections as flow collections vs block collections that could additionally be considered? At least, we output YAML in block style, and therefore would expect no quoting for string containing above characters.

A more elaborated solution might also consider the local context of a string value (in flow collection/in block collection/outside collection).

Our example file reads

TranslatorSpringTest:
  namedParameters: Test with parameter 0 = "{{param0}}" and parameter 1 = "{{param1}}".

and could be read and output as is with Jackson 2.10.3, but got converted to

TranslatorSpringTest:
  namedParameters: "Test with parameter 0 = \"{{param0}}\" and parameter 1 = \"{{param1}}\"."

with Jackson 2.11.3.

@cowtowncoder
Copy link
Member

All low-level formatting details are handled by SnakeYAML (for 2.x, and snakeyaml-engine, its sequel for 3.0).
YAMLGenerator.Feature has some options to change settings passed to SnakeYAML.
So, changes are possible if they are supported by SnakeYAML and can then be ideally expressed as simple on/off options; or, if someone has more time and interest, using some more versatile settings.

However I'd prefer not want to expose specific SnakeYAML configuration options partly as 2.x/3.x will use different backends.

@cowtowncoder cowtowncoder added the yaml Issue related to YAML format backend label Nov 22, 2020
@cowtowncoder
Copy link
Member

Another possibility (for which PRs would be accepted) would be pluggable handlers that could indicate if certain output mode was to be forced. That could be implemented in a way to prevent close-coupling, if suitable response values could be enumerated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
yaml Issue related to YAML format backend
Projects
None yet
Development

No branches or pull requests

2 participants