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:
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?
YAML supports single line comments. # this is single line comment.
In order to add comments to a YAML file, you simply have to use the # (hashtag symbol) at the start of the line. For example, below is an example of one commented line in a YAML file.
SnakeYAML allows you to read a YAML file into a simple Map object or parse the file and convert it into a custom Java object. Depending on your requirements you can decide in which format you want to read your YAML files.
Since the implementation is not thread safe, different threads must have their own Yaml instance.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With