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

Parse YAML Keys with dots as dereferenced Map #431

Open
theAkito opened this issue Sep 13, 2023 · 5 comments
Open

Parse YAML Keys with dots as dereferenced Map #431

theAkito opened this issue Sep 13, 2023 · 5 comments
Labels
yaml Issue related to YAML format backend

Comments

@theAkito
Copy link

When parsing something like this

conf.user.password: "secret"

it should be parsed as

conf:
  user:
    password: "secret"

but it is parsed with the dots, as if those were valid key names.

Is there a configuration option for this? I have found no documentation whatsoever on this.

@cowtowncoder cowtowncoder added the yaml Issue related to YAML format backend label Sep 15, 2023
@cowtowncoder
Copy link
Member

I don't think YAML spec consider these identical. Some libraries/frameworks can do that but I don't think that is conceptually part of YAML.

Lower level YAML decoding for jackson-dataformat-yaml is handled by SnakeYAML library which would transparently process dotted names, if that was mandated by YAML specification.

@theAkito
Copy link
Author

@cowtowncoder

Thank you for your response! 👋🏻

I don't think YAML spec consider these identical. Some libraries/frameworks can do that but I don't think that is conceptually part of YAML.

Lower level YAML decoding for jackson-dataformat-yaml is handled by SnakeYAML library which would transparently process dotted names, if that was mandated by YAML specification.

Yes, I've read that, too & it makes sense to a certain degree.

It's just that, I have read & experienced myself in projects, that the YAML .properties file for Spring Boot does exactly that & I assumed it must be somehow built into some YAML in Java, anyway.

Is it possible to use Jackson to parse a generic YAML source like that? What would I do about that?

I'm currently not sure which solution I would use for such a case.

For context, I need this for the Rancher API, which converts some YAML into this dotted format & I need to reverse those key value pairs into their original hierarchy.

@cowtowncoder
Copy link
Member

I can see how an option to expand such notation on reading would be useful: I think the way it should work would be for underlying YAMLParser to specifically expose a Stream as if structure existed. This is actually quite like how Properties (jackson-dataformat-properites) works; it splits dotted names (configurable to use different separators). And possibly do the reverse on writing, to allow combining single-property paths.

However, although I can see how it should conceptually work, implementing this is a different matter, not trivial thing to achieve.

But if anyone has time and interest, I'd be happy to help.
I just don't have bandwidth to drive such feature myself.

@theAkito
Copy link
Author

@cowtowncoder

That makes sense.

Since I wasn't sure, what to do about it, I am in the process of implementing my own way of handling this in Kotlin.

I am however not sure, if this would be of any use for an official implementation in regards to this project, since I'm not sure some Kotlin stuff is javafiable in a reasonable way.

It's far from finished yet, so I don't know, yet, though.

Maybe I can provide the implementation, once I'm done & then we will see, if that's of any use. 👍🏻

@cowtowncoder
Copy link
Member

Sounds good @theAkito. Kotlin components cannot be included in (or depended on by) core components, but an implementation could definitely help inspire improvements in form of Java code (just as an example).

Besides, similar path expansion/contraction might be useful for other formats, not the least json. In fact, building something that would expand/contract document expressed as JsonNode (regardless of format it came from or becomes written as) might be something nice to add to jackson-databind.
If so, it could be used as a pre-/post-processing step.

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