-
-
Notifications
You must be signed in to change notification settings - Fork 149
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: multiline string will always be quoted when line has trailing space #366
Comments
The first thing is that you would also need to include actual code -- what Due to complexity of YAML rules for handling white-space, it may be tricky to determine whether behavior makes sense or not tho. |
Also this is wrong repo, moving. |
I have the same issue. private static final ObjectMapper MAPPER = JsonMapper.builder(new YAMLFactory()
.enable(YAMLGenerator.Feature.MINIMIZE_QUOTES)
.enable(YAMLGenerator.Feature.INDENT_ARRAYS_WITH_INDICATOR)
.enable(YAMLGenerator.Feature.ALWAYS_QUOTE_NUMBERS_AS_STRINGS)
.disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER))
.enable(JsonReadFeature.ALLOW_SINGLE_QUOTES)
.build().findAndRegisterModules(); Example YAML: someKey:
otherKey.properties: |-
# comment with trailing whitespace
property1=my-value This will be converted to someKey:
otherKey.properties: "# comment with trailing whitespace \nproperty1=my-value" See example Maven project: Build and run
|
@nylend95 And this is with 2.17.2? |
Yes! Forgot to include that in the description, but as you can see in my example, I have configured |
On issue itself, just to make sure I understand what is expected: it is to keep "use literal block style" usage, even if "minimize quotes" is desired?
@nylend95 I don't see the first setting in your example tho? I am not sure if above is doable, might be? (or whether it's easy to do if so). But one thing that is often helpful is to contribute PR for failing test (under |
Ah, yes! Our use cases is to keep block style where suitable, and no quotes on single lines if possible. I have yet to dig into the code to see how/if these settings are triggering different behavior. With both of these features enabled, I still see the same behavior as before. JsonMapper.builder(new YAMLFactory()
.enable(YAMLGenerator.Feature.LITERAL_BLOCK_STYLE)
.enable(YAMLGenerator.Feature.MINIMIZE_QUOTES)
.enable(YAMLGenerator.Feature.INDENT_ARRAYS_WITH_INDICATOR)
.enable(YAMLGenerator.Feature.ALWAYS_QUOTE_NUMBERS_AS_STRINGS)
.disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER))
.enable(JsonReadFeature.ALLOW_SINGLE_QUOTES)
.build().findAndRegisterModules(); The block style string is converted to a single line when at least one of the lines end with a whitespace. I don't know if it should be considered a bug or not, but I find it a bit weird behavior that a change in a trailing space on a single line should trigger that the field will be converted to a single line. If you/FasterXML decides that this behavior is wrong, I can get a PR up for the failing test and then we can take it from there. |
From description this does appear to be a flaw. One thing to note is that the low-level encoding is by SnakeYAML so it may be down to question of interaction between Jackson YAML module and SnakeYAML generator. And yes, we could use help here with failing test! |
I can see if I can reproduce this with just SnakeYAML. If I can, I guess it would be better to open an issue towards SnakeYAML instead? |
Yes, if it is something reproducible with SnakeYAML. If it turns out it is due to way Jackson uses SnakeYAML then needs to be fixed here of course. |
I have created PR #501 based on the successful test function SimpleGenerationTest.testLiteralBlockStyle. |
Had a quick look at code, and style Jackson module passes to SnakeYAML is Leaving open if anyone has any ideas. |
I am generating a yml file with the below settings:
This will write multiline strings as following:
However if i put a space between "test" and the following line break it will quote the string as if MINIMIZE_QUOTES was disabled:
The text was updated successfully, but these errors were encountered: