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

Nested Yaml question #249

Open
sknot-rh opened this issue Mar 31, 2021 · 5 comments
Open

Nested Yaml question #249

sknot-rh opened this issue Mar 31, 2021 · 5 comments
Labels
yaml Issue related to YAML format backend

Comments

@sknot-rh
Copy link

Hi. I was using version 2.10.5 and my code was able to process nested yamls correctly. With version 2.12.2 I am not able to make it work.

Code:

YAMLMapper yamlMapper = new YAMLMapper(new YAMLFactory().enable(YAMLGenerator.Feature.MINIMIZE_QUOTES));
yamlMapper.writerWithDefaultPrettyPrinter().writeValue(new File("output.yaml"), resource.getResource());

Output with version 2.10.5

---
apiVersion: v1
kind: MyKind
metadata:
  name: example
data:
  config.yaml: |
    lowercaseOutputName: true
    rules:
    - pattern: "metric<name=(.+)><>(\\w+)"
      name: "metric_$1_$2"
      type: "GAUGE"

Output with version 2.12.2

---
apiVersion: v1
kind: MyKind
metadata:
  name: example
data:
  config.yaml: "lowercaseOutputName:\
    \ true\nrules:\n- pattern: \"metric<name=(.+)><>(\\\\w+)\"\n  name:\
    \ \"metric_$1_$2\"\n  type: \"GAUGE\"\n"

Am I missing some serialization option?

@cowtowncoder
Copy link
Member

I assume value of config.yaml is String (including definition of Java value being serialized would be useful here).
If so, contents being serialized are identical but definitely look ugly.

Unfortunately I don't know what might have changed here. It might make sense to see what 2.11.4 does to maybe pinpoint change(s) to logic. I suspect this is related to logic wrt escaping of unsafe values.
One setting to maybe try would be YAMLGenerator.Feature.LITERAL_BLOCK_STYLE

@cowtowncoder cowtowncoder added the yaml Issue related to YAML format backend label Mar 31, 2021
@sknot-rh
Copy link
Author

sknot-rh commented Apr 1, 2021

I tried YAMLGenerator.Feature.LITERAL_BLOCK_STYLE with no luck.
I also tried various versions. Thi behaviour begins since 2.11.0 (included)

@sknot-rh
Copy link
Author

sknot-rh commented Apr 1, 2021

I did some digging.

The difference happens there:
https://github.com/FasterXML/jackson-dataformats-text/blob/2.10/yaml/src/main/java/com/fasterxml/jackson/dataformat/yaml/YAMLGenerator.java#L982
https://github.com/FasterXML/jackson-dataformats-text/blob/2.11/yaml/src/main/java/com/fasterxml/jackson/dataformat/yaml/YAMLGenerator.java#L987

The affected condition (this._valueNeedsQuoting(text)) returns false on 2.10.5 but true in 2.11.x
The text is whatever string containing quotes.

@cowtowncoder
Copy link
Member

Yes. This is difficult because leaving out quoting is dangerous. But I know that use case of "just leave out minimally processed chunk to use in k8s manifests (Helm Charts, whatever)" is pretty common and this is problematic for user-editability.

This is probably related to #246.

@cowtowncoder
Copy link
Member

Also forgot to mention that a unit test would be needed to show details (explanation alone is not sufficient to reproduce).
It would be good to have a small reproduction, but I'll proceed with #246 since I think that will resolve this issue too.

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