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

[Yaml] [Suggestion] Ability to add comments #269

Closed
PeachesMLG opened this issue May 8, 2021 · 6 comments
Closed

[Yaml] [Suggestion] Ability to add comments #269

PeachesMLG opened this issue May 8, 2021 · 6 comments
Labels
duplicate Issue is (closed as) a duplicate of another issue yaml Issue related to YAML format backend

Comments

@PeachesMLG
Copy link

Not sure if this is the right place to ask, and appologies if this is already possible.

Would be cool if we could annotate fields with like @YamlComment(comment = "The yaml comment here") to add a comment to the file

Not sure how hard this would be, im too dumb to understand this codebase, but I think it would be a cool idea :)

@yawkat
Copy link
Member

yawkat commented May 8, 2021

At the moment, jackson-databind has no machinery to pass on format-specific information like this. Also see #36 for yaml, and #254 for toml.

@cowtowncoder
Copy link
Member

cowtowncoder commented May 8, 2021

Right, there are at least these problems:

  1. There is no generic comment writing functionality (databinding is format-agnostic and must stick to using methods common to all backends). YAML, XML, Properties have comments at least (and JSON arguably with non-standard features enabled)
  2. Even if there was, figuring out location for comments is tricky: where should it end? (before key/value, after, in-between?) Adding comment in some place would be more doable, but users probably want more control than is easy to provide.

So adding an annotation itself is not difficult, nor exposing it via AnnotationIntrospector. Difficult parts are wiring via JsonGenerator and defining expected useful semantics wrt placement of comment.

@cowtowncoder cowtowncoder added the yaml Issue related to YAML format backend label May 27, 2021
@Charlinjoeaht
Copy link

Even today, I am looking for this solution. Let me know if anyone finds any solution to achieve this

@cowtowncoder
Copy link
Member

One thing I forgot to note is that use of @JsonRawValue annotation might work, to some degree. It allows injecting any String as a value. I am not saying it provides what is asked here but just that it could work for some usage.

@big-andy-coates
Copy link

@cowtowncoder - this issue can be closed as a duplicate of #36, if you're so inclined. :)

@cowtowncoder
Copy link
Member

Ah yes; will do so.

@cowtowncoder cowtowncoder added the duplicate Issue is (closed as) a duplicate of another issue label Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate Issue is (closed as) a duplicate of another issue yaml Issue related to YAML format backend
Projects
None yet
Development

No branches or pull requests

5 participants