views:

3249

answers:

8

There are at least 4 YAML implementations listed at yaml.org. Which one of these (or another) would you recommend, and why?

There are two ways you could answer this question, either by voting for one of the 4, or by giving a good answer that compares them or strongly justifies one of them. I'll add the 4 mentioned so people can vote, but I'd love a longer justified answer if you could write one.

A: 

JvYAML

Nick Fortescue
+1  A: 

SnakeYAML

Nick Fortescue
A: 

yamlbeans

Nick Fortescue
A: 

JYaml

Nick Fortescue
+10  A: 
  • JvYaml - an old unsupported library (no issues are fixed)
  • SnakeYAML - a port from the latest PyYAML. The most advanced parser and emitter. Support for type safe collections. 97% code coverage. Proper BOM support. Good documentation with examples. Maven 2.
  • YamlBeans - good JavaBean support
  • JYaml - many open issues but works for a lot of applications. It appears as a first link in Google when search for 'java yaml'!
+14  A: 

Andrey gave a thorough summary of all four libraries. Here's my personal experience with two of them.

At my job we use both JYaml and SnakeYAML. We started with JYaml in the 2007-2008 timeframe when it appeared to be active. It has API similarities with XStream, which is a benefit for us. I introduced SnakeYAML in mid-2009 when I encountered a bug in JYaml and noticed there have been no new JYaml releases since 2007-08-19.

SnakeYAML has been very solid for us. It is a faithful port of PyYAML, which itself is considered good enough as to be a reference implementation of YAML 1.1.

Being a port of PyYAML, you will get very good interop between Java and Python if that's important to you as long you're not trying to serialize native types (beyond the basics: Strings, numbers, lists, maps).

Being as true to the YAML 1.1 spec as it is, SnakeYAML can be used as a YAML validator. Some of the only difficulty I've had with SnakeYAML has been getting it to load YAML generated from Perl via YAML::Syck. In almost all cases YAML::Syck was generating invalid YAML.

One drawback of SnakeYAML is that it's primarily meant to be a library for Java ↔ YAML binding. Using it as a general purpose YAML loader should be simpler. A low-level API is available, but you lose implicit typing and native object construction unless you add them back in. If you don't control the YAML production, then your code bears the burden of telling SnakeYAML how to handle unrecognized tags (see my enhancement request for more on this).

The maintainers provided example code on how to extend SnakeYAML to fit my use case. It's a measure of their good design that it was possible and a measure of their responsiveness that they provided the direction.

toolbear74
+1  A: 

Hi, I am still using JvYaml and just can tell something about this one. It is really easy to use and supports really a lot. But it got really a big disadvantage: If there is an error the engine does not tell where the error occured. So its a kind of trial and error then. I changed some things in the sourcecode for myself to have a bit more comfort, but it still got situation where no column or line number is shown to the user. Since I found this question and answer of yaml, I think I'll give SnakeYaml a try for my next new programm.

takidoso
Clear error reporting is an important SnakeYAML feature. It reports the line and the column.