YAML Base

Base classes for YAML implementation

License

License

Categories

Categories

Net
GroupId

GroupId

net.pwall.yaml
ArtifactId

ArtifactId

yaml-base
Last Version

Last Version

1.2
Release Date

Release Date

Type

Type

jar
Description

Description

YAML Base
Base classes for YAML implementation
Project URL

Project URL

https://github.com/pwall567/yaml-base
Source Code Management

Source Code Management

https://github.com/pwall567/yaml-base.git

Download yaml-base

How to add to project

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

Dependencies

compile (1)

Group / Artifact Type Version
net.pwall.json : jsonutil jar 5.0

test (1)

Group / Artifact Type Version
junit : junit jar 4.13.1

Project Modules

There are no modules declared in this project.

yaml-base

Build Status License: MIT Maven Central

Base classes for YAML implementation.

The specification of YAML is contained in a document entitled YAML Ain't Markup Language (YAML™) Version 1.2, and that document (in §1.3. Relation to JSON) states "YAML can … be viewed as a natural superset of JSON". Accordingly, each of the classes in this library derives from the equivalent class in the jsonutil library (and that library is a transitive dependency of this one). A tree of YAMLNode objects can therefore be navigated as if it were a tree of JSONValues.

Reference

YAMLNode

The root interface for all YAML nodes. It extends JSONValue, and it adds a single method:

  • String getTag(): return the tag associated with the node

Each of the implementing classes has a constructor that takes a tag in the form of a String, along with constructors that supply a default tag name (from the specification §10.3. Core Schema). The tag name is immutable and no setter is provided.

YAMLScalar

This is a marker interface, implemented by the implementation classes for the various forms of YAML scalar. It extends YAMLNode and adds no additional methods.

YAMLString

YAMLString extends JSONString and implements YAMLScalar. The JSONString.getValue() function returns the value.

Example:

        YAMLString yamlString = new YAMLString("Hello!");
        System.out.println(yamlString.getValue()); // prints Hello!

YAMLInt

YAMLInt extends JSONInteger and implements YAMLScalar. The JSONInteger.getValue() function returns the value.

Example:

        YAMLInt yamlInt = new YAMLInt(3 * 3 * 3);
        System.out.println(yamlInt.getValue()); // prints 27

YAMLLong

YAMLLong extends JSONLong and implements YAMLScalar. The YAMLLong.getValue() function returns the value.

Example:

        YAMLLong yamlLong = new YAMLLong(1234567812345678L);
        System.out.println(yamlLong.getValue()); // prints 1234567812345678

YAMLDecimal

YAMLDecimal extends JSONDecimal and implements YAMLScalar. The YAMLDecimal.getValue() function returns the value.

Example:

        YAMLDecimal yamlDecimal = new YAMLDecimal(new BigDecimal("123.45"));
        System.out.println(yamlDecimal.getValue()); // prints 123.45

YAMLBoolean

YAMLBoolean extends JSONBoolean and implements YAMLScalar. The YAMLBoolean.getValue() function returns the value.

Example:

        YAMLBoolean yamlBoolean = YAMLBoolean.TRUE;
        System.out.println(yamlBoolean.getValue()); // prints true

YAMLSequence

YAMLSequence extends JSONSequence<YAMLNode> and implements YAMLNode. JSONSequence<YAMLNode> implements List<YAMLNode>, so all of the functionality of the List interface is available to access the members of the sequence.

Example:

        YAMLSequence yamlSequence = new YAMLSequence(Arrays.asList(new YAMLString("Hello"), new YAMLString("World")));
        for (YAMLNode node : yamlSequence)
            System.out.println(node); // prints Hello (first time), World (second time)

YAMLMapping

YAMLMapping extends JSONMapping<YAMLNode> and implements YAMLNode. JSONMapping<YAMLNode> implements Map<String, YAMLNode>, so all of the functionality of the Map interface is available to access the members of the mapping.

Example:

        Map<String, YAMLNode> map = new HashMap<>();
        map.put("greeting", new YAMLString("Hello"));
        map.put("who", new YAMLString("World"));
        YAMLMapping yamlMapping = new YAMLMapping(map);
        System.out.println(yamlMapping.get("greeting")); // prints Hello
        System.out.println(yamlMapping.get("who")); // prints World

YAMLDocument

YAMLDocument is a container to hold the results of a YAML parse operation. It contains the root node of the parsed document, along with the version number from the %YAML directive (if provided).

Constructors:

  • YAMLDocument(YAMLNode rootNode, int majorVersion, int minorVersion)
  • YAMLDocument(YAMLNode rootNode) (defaults majorVersion to 1 and minorVersion to 2)

Functions:

  • YAMLNode getRootNode()
  • int getMajorVersion()
  • int getMinorVersion()

Dependency Specification

The latest version of the library is 1.2, and it may be obtained from the Maven Central repository.

Maven

    <dependency>
      <groupId>net.pwall.yaml</groupId>
      <artifactId>yaml-base</artifactId>
      <version>1.2</version>
    </dependency>

Gradle

    testImplementation 'net.pwall.yaml:yaml-base:1.2'

Gradle (kts)

    testImplementation("net.pwall.yaml:yaml-base:1.2")

Peter Wall

2021-04-20

Versions

Version
1.2
1.1
1.0
0.2
0.1