Skip to content

Default YAML mapper quotes "y" as a key #278

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

Closed
tcrespog opened this issue Jun 25, 2021 · 2 comments
Closed

Default YAML mapper quotes "y" as a key #278

tcrespog opened this issue Jun 25, 2021 · 2 comments

Comments

@tcrespog
Copy link

tcrespog commented Jun 25, 2021

Hi, after upgrading from the 2.11.4 version of the library to the 2.12.x line I've noticed that a default YAML mapper...

ObjectMapper mapper = new ObjectMapper(new YAMLFactory());

...is quoting the y character when found as a key, whereas other single character keys (or longer string keys for that matter) are not being quoted. For example, the code...

ObjectMapper defaultMapper = new ObjectMapper(new YAMLFactory());

Map<String, Integer> map = new HashMap<>();
map.put("x", 1);
map.put("y", 2);
map.put("z", 3);
defaultMapper.writeValueAsString(map);

...generates the YAML...

---
x: 1
"y": 2
z: 3

...whereas using 2.11.4 it generates:

---
x: 1
y: 2
z: 3

What is the reason behind such new behavior? Thanks.

(I've uploaded a sample repo (https://github.com/tcrespog/jackson-yml-test) with a simple test that reproduces the aforementioned behavior)

@cowtowncoder
Copy link
Member

No problem -- yes, it is a YAML oddity needed to avoid accidental coercion. Glad you found out the answer!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants