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 J小号ON-P (JSR 374). With this idea in mind, eo-yaml took shape.
与市场上的其他YAML库不同,eo-yaml是完全封装的,并具有API优先设计-用户仅使用几个直观的Java接口,所有实现都被隐藏了。 这也为不同的提供者打开了大门:您不喜欢参考实现? 太酷了,自己实现这些接口并继续使用相同的API。
Usage
构建,读取,转储或加载YAML的入口点是classcom.amihaiemil.eoyaml.Yaml。 这是一个简短的概述:
Building YAML
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
印刷的YAML将是:
# Project Team
architect: amihaiemil
# DevOps Tools
devops:
- rultor
- 0pdd
developers:
- amihaiemil
- salikjan
- SherifWally
Reading YAML
读取YAML非常简单(您可以从文件,来自输入流或从串):
final YamlMapping team = Yaml.createYamlInput(
new File("team.yml")
).readYamlMapping();
Dumping YAML (Bean-to-Yaml)
final YamlMapping student = Yaml.createYamlDump(
new Student(...)//bean with getters and setters
).dump();
JDK Integration
该API尽可能与JDK集成:例如,YamlSequence实施Iterable<YamlNode>还有一个YamlStream (a collection of more YAML documents)实施Java 8's Stream API.
Java Module
该库现在将主要与Java 8兼容。 但是,它被打包为模块,因此,如果您使用的是Java 9或更高版本,则可以按原样使用它。
Easy Extension
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.
Often and Fast Releases
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.
总之,我们希望我们对产品有一个很好的概述,并希望看到更多的用户尝试一下。 如果您有任何问题,问题或功能要求,请随时打开Github Issue,我们将尽力为您提供帮助。