jackson-dataformats-text icon indicating copy to clipboard operation
jackson-dataformats-text copied to clipboard

[Yaml] [Suggestion] Ability to add comments

Open PeachesMLG opened this issue 4 years ago • 4 comments

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 :)

PeachesMLG avatar May 08 '21 11:05 PeachesMLG

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.

yawkat avatar May 08 '21 14:05 yawkat

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 avatar May 08 '21 19:05 cowtowncoder

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

Charlinjoeaht avatar Jun 01 '22 08:06 Charlinjoeaht

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.

cowtowncoder avatar Jun 26 '22 22:06 cowtowncoder