Tuesday, November 3, 2009

Java libraries for YAML

This is my overview of the state of different YAML libraries for Java. I do not claim it is complete (yes, I am biased) but it is my vision for today. Feel free to correct me.

  • JvYaml, v=0.2.1: the project is dead. No issue is fixed. The developer is now maintaining another project - JvYAMLb
  • JvYAMLb is a YAML processing library for Java, used by JRuby, v=0.2.5. I did not even evaluate the project because of a few dependencies on JRuby.
  • JYaml, v=1.3: last release is more then 2 year old. Many open bugs. I do not know whether it is maintained. Google puts this library to the top. Does it mean that it is the most wide spread ?
  • YamlBeans, v=0.93: since the parser and emitter are based on the JvYaml implementation it does not cover the whole 1.1 specification.
    Implicit types are not supported (http://yaml.org/type/index.html)
    Implementation does not follow the recommended way (http://yaml.org/spec/1.1/#id859333)
    The document must be a JavaBean. Empty constructor is required. Immutable objects are not supported.
  • SnakeYAML, v=1.5. Unique features:
- Complete 1.1 YAML spec is implemented
- strong commitment to cross-language compatibility (as less global tags as possible)
- comprehensive documentation
- Maven 2 artifacts (including sources.jar and javadoc.jar)
- complete support for recursive objects (they can be parsed and emitted)
- 98% test coverage
- support for immutable instances
- collections in JavaBeans do not require global tags (other libraries need to configure additional runtime information which is required because of erasure)
- readable error reporting (with line numbers)

In fact I am not aware of any feature which is present in any library but not implemented in SnakeYAML. Nevertheless Google puts JYaml much higher then SnakeYAML and YamlBeans has much more downloads then SnakeYAML.
What is missing in SnakeYAML ? Why developers prefer to use another library ? What can be improved in SnakeYAML ?

4 comments:

Scot said...

It would probably help if the documentation was a bit more organized and expanded - at the moment it looks like more a FAQ than "real" documentation.

Also, I can't find online JavaDocs (which I could really use right this second), which is something most projects provide (if there are already Javadocs online then they need to made more obvious).

A basic tutorial would also be helpful.

Andrey Somov said...

If you mean documentation for SnakeYAML there are a couple of wiki pages:
http://code.google.com/p/snakeyaml/w/list

1.5 reports (including Javadoc) is here:
http://snakeyamlrepo.appspot.com/releases/1.5/site/project-reports.html

I have added a reference to JavaDoc on the main project page.

Malte said...

I was using jvYaml and was disapointed after a while since I wasted my time searching syntactical errors in my documents because no usable error-messages came out like line number. I scewed around in its source-code to get at least sometimes line-numbers.
Right now I try SnakeYaml for a new project being pleased so far. I think I will switch some projects of mine to SnakeYaml as well.
But what I am missing in YAML-comunities so far (may be I just have not found the right one) is A kind of Listener implementation So I could produce yaml-files with comments basing on yaml-files that already exist.
may be You know some implementation of this kind of feature?

Andrey Somov said...

Feel free to create an issue in SnakeYAML (http://code.google.com/p/snakeyaml/issues/list).
I must say I did not quite catch you. Do you want just to add comments to your YAML documents ?
SnakeYAML has low-level API (http://code.google.com/p/snakeyaml/wiki/Documentation#Low_Level_API) which gives you a possibility to generate events. Based on this you can create your own documents but it is not a simple task.