YAML API

A Jackson-like API to create YAML nodes (based on SnakeYAML)

License

License

GroupId

GroupId

com.github.autermann
ArtifactId

ArtifactId

yaml
Last Version

Last Version

1.0.3
Release Date

Release Date

Type

Type

jar
Description

Description

YAML API
A Jackson-like API to create YAML nodes (based on SnakeYAML)
Project URL

Project URL

https://github.com/autermann/yaml
Source Code Management

Source Code Management

https://github.com/autermann/yaml

Download yaml

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.autermann/yaml/ -->
<dependency>
    <groupId>com.github.autermann</groupId>
    <artifactId>yaml</artifactId>
    <version>1.0.3</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.autermann/yaml/
implementation 'com.github.autermann:yaml:1.0.3'
// https://jarcasting.com/artifacts/com.github.autermann/yaml/
implementation ("com.github.autermann:yaml:1.0.3")
'com.github.autermann:yaml:jar:1.0.3'
<dependency org="com.github.autermann" name="yaml" rev="1.0.3">
  <artifact name="yaml" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.autermann', module='yaml', version='1.0.3')
)
libraryDependencies += "com.github.autermann" % "yaml" % "1.0.3"
[com.github.autermann/yaml "1.0.3"]

Dependencies

compile (3)

Group / Artifact Type Version
com.google.guava : guava jar 18.0
org.yaml : snakeyaml jar 1.15
joda-time : joda-time jar 2.8.1

test (2)

Group / Artifact Type Version
junit : junit jar 4.12
org.hamcrest : hamcrest-all jar 1.3

Project Modules

There are no modules declared in this project.

YAML API Build Status

A Jackson-like API to create YAML nodes (based on SnakeYAML).

Example Usage

Maven

Add this to your dependencies:

<dependency>
     <groupId>com.github.autermann</groupId>
     <artifactId>yaml</artifactId>
     <version>1.0.3</version>
</dependency>

Note: Requires JDK 1.8 or higher

Creating nodes

YamlNodeFactory factory = YamlNodeFactory.createDefault();
YamlMapNode mnode = factory.orderedMapNode();
mnode.put("hello", "world")
     .put("key", true)
     .put("integer", 2)
     .put("double", 42.0d)
     .put("time", DateTime.now(DateTimeZone.UTC));
mnode.putSequence("message")
     .add("this").add("is").add("snakeyaml-api");
mnode.putPairs("pairs")
     .put("pair1", "pair1")
     .put("pair1", "pair1")
     .put("pair2", "pair2");

byte[] bytes = new byte[240];
new Random().nextBytes(bytes);
mnode.put("binary", bytes);

mnode.dump(System.out);
!!omap
hello: world
key: true
integer: 2
double: 42.0
time: 2013-11-06T02:33:08.701Z
message: [this, is, snakeyaml-api]
pairs: !!pairs
  pair1: pair1
  pair1: pair1
  pair2: pair2
binary: !!binary |-
  gePJ2SRk0zJFl3B/pD+jDSqAVwZcusf36lZ/LrTHA6fkBna9OJAXhItSf+VP2ORk92LIF2ldTAFFZaUu
  KNto57j82DpT2aM4ty6Ta5WE1RcOFtT+Sfc3VC0t5JfvTFQVMuvsWvvxLQ7/1W/LHKswQbWb7dwsGgYs
  O1DqFGnkJgTHH+7pp1yNf4G1A/SchS9stc0us3OzjAku/b8xSdlgRLMz195F9mEDvfW/BGTvQLjbSSIZ
  Nr5w92nw1ecXCni2dUCNk7VQERQVA8fB1YN89XluLuW+xY4kcATEj6+CzuRRJK6NS90kJ1SmM6/mDOu3

Reading Nodes

YamlNode loaded = new Yaml().load(/*...*/);
if (loaded.isMapping()) {
    YamlMappingNode node = loaded.asMapping();
    node.path("hello").textValue(); // world
    node.path("binary").binaryValue(); // byte[240]
    node.path("message").asSequence().get(2); //snakeyaml-api
}

Anchors and Aliases

As long they are not recursive, they are supported:

YamlMapNode a = factory.mapNode().put("value", true);
YamlMapNode root = factory.orderedMapNode().put("a", a).put("b", a);
System.out.println(root.dump());
!!omap
a: &id001
  value: true
b: *id001
YamlNode node = YAML.load(/* ... */);
System.out.println(node.path("a") == node.path("b")); // == true

License

The project is licensed under the Apache License, Version 2.0

Copyright 2013 Christian Autermann

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Versions

Version
1.0.3
1.0.2
1.0.1
1.0.0