FasterXML / jackson-dataformats-text

Uber-project for (some) standard Jackson textual format backends: csv, properties, yaml (xml to be added in future)
Apache License 2.0
404 stars 148 forks source link

YAML: consider starting `#` and ending `:` as quotable characters #465

Closed MikeEdgar closed 7 months ago

MikeEdgar commented 7 months ago

Scalar values starting with # or ending with : should be quoted. Currently, SnakeYAML will single-quote them automatically. This change will proactively trigger the double quote style used for other values that require quotes when MINIMIZE_QUOTES is enabled.

cowtowncoder commented 7 months ago

@MikeEdgar one procedural thing before merging: if we don't yet have CLA (only needs to be sent once for all contributions, before merging the first), it's here:

https://github.com/FasterXML/jackson/blob/master/contributor-agreement.pdf

and it's usually easiest to print, fill & sign, scan/photo, email to cla at fasterxml dot com. Once we have it I'll go ahead and merge this.

Thank you very much for contributing this (esp. great to have test coverage); looking forward to merging it.

oliversaggau commented 4 months ago

I'm not quite sure if this is/was desired behavior, as the original description only states

Scalar values starting with # or ending with : should be quoted.

~But upgrading springdoc in our project to version 1.8.0 (which uses jackson version 2.17 with this change) in our project resulted in all scalar values being double-quoted instead of single-quoted in the generated .yaml file, not only the ones starting with # or ending with :~ Nevermind me, it indeed only affected values starting with #. Just ignore my comment 🙈

cowtowncoder commented 4 months ago

@oliversaggau Thank you for double-checking :)

ivangal2 commented 2 months ago

@MikeEdgar , can you please explain/elaborate what was wrong with the single quotes before? And why do you think the double quotes are necessary for scalar values starting with # char?

MikeEdgar commented 2 months ago

@ivangal2 it was inconsistent. Jackson would quote some values with " and SnakeYAML would detect other values and automatically use '. The point of this PR was to make use of one quoting style when quotes are automatically added.

Weinan-Zhang commented 1 month ago

one question, what if single quote(') is needed to keep consistency, is there a way to configure(select) the style of quoting(single or double), thanks!

cowtowncoder commented 1 month ago

@Weinan-Zhang I am not 100% sure but I think there is no option for using single quote. If this is something you would like, feel free to file an issue requesting such feature (and if you have time and interest possibly even contribute a PR for adding). I don't know whether this would be easy to do -- considering complexity in configuring details of SnakeYAML output used by this module -- but it should be doable.