Since Java does not have a standard API for YAML and since, starting YAML 1.2, the format is supposed to be a superset of JSON, we decided to create a parser which closely follows the API and encapsulation of JSON-P (JSR 374). With this idea in mind, eo-yaml took shape.
Unlike other YAML libraries on the market, eo-yaml is fully encapsulated and has an API-first design -- the user works with only a few intuitive Java Interfaces, all the implementations being hidden. This also opens the door for different providers: you don't like the reference implementation? Cool, implement those interfaces yourself and keep using the same API.
The entry point for building, reading, dumping or loading YAML is class
com.amihaiemil.eoyaml.Yaml. Here's a short overview:
final YamlMapping team = Yaml.createYamlMappingBuilder() .add("architect", "amihaiemil") .add( "devops", Yaml.createYamlSequenceBuilder() .add("rultor") .add("0pdd") .build("DevOps Tools") ).add( "developers", Yaml.createYamlSequenceBuilder() .add("amihaiemil") .add("salikjan") .add("SherifWally") .build() ).build("Project Team"); System.out.println(team); //toString() methods overriden to pretty-print the YAML
The printed YAML will be:
# Project Team architect: amihaiemil # DevOps Tools devops: - rultor - 0pdd developers: - amihaiemil - salikjan - SherifWally
Reading YAML is as simple as (you can read from a
File, from an
InputStream or from a
final YamlMapping team = Yaml.createYamlInput( new File("team.yml") ).readYamlMapping();
final YamlMapping student = Yaml.createYamlDump( new Student(...)//bean with getters and setters ).dump();
The API is integrated with the JDK where possible: for instance, a
Iterable<YamlNode> and a
YamlStream (a collection of more YAML documents) implements Java 8's Stream API.
The library is and will be primarily Java 8 compatible. However, it is packaged as a Module, so it can be used as such if you are on Java 9 or higher.
Since it is based on interfaces, you can easily create your own decorators or implementations on top of the existing ones to enhance or create new functionality. More in the Wiki.
At the moment we release a new version containing fixes and features about once a week. We have a smart chatbot that lets us release to Maven Central with only one comment. See how the latest release went here.
To conclude, we hope we have provided a good overview of the product and hope to see as many users try it as possible. Feel free to open a Github Issue for any problem, question or feature request you may have, we'll try to help as fast as possible.