Xyene
Xyene

Reputation: 2364

Adding a Comment to a Node With SnakeYaml

As part of a large project I am working on, I am constructing a YAML file in memory, and then dumping it to a file, using SnakeYaml in this entire process. My YAML file is around 500 lines long and meant to be used by people who have no programming experience whatsoever, so comments on most nodes is a must. My past three hours have been spent staring at the SnakeYaml Documentation, as well as Googling a fair bit, but with no results. I can conclude one of three things:

  1. I may have missed it completely.
  2. Its not there (unlikely, if it does exists).
  3. Its not possible.

I'm leaning towards the third, but before I write my own YAML dumper, I wished to ask the StackOverflow community whether this is possible? So, is it? Something among the lines of yamlfile.setComment("a.random.node", "Its a random node!"); would be bliss, but it doesn't matter to me if it isn't anywhere close to as simple.

In the case that it is not, could someone give me some pointers as to what I should do to accomplish this?

Upvotes: 7

Views: 4052

Answers (1)

Andrey
Andrey

Reputation: 3001

Since the comments are not part of the representation tree, they are ignored by SnakeYAML. Since a YAML document is nothing but a text document, any Template processor can be used.

Upvotes: 3

Related Questions