Skip to content

Read and write YAML in Java using the Jakarta JSON API

License

Notifications You must be signed in to change notification settings

xlate/yaml-json

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

yaml-json : JSON API for YAML

build Quality Gate Status Maven Central javadoc

Read and write YAML in Java using the Jakarta JSON API (JDK 11+)

Basic Usage

Reader reader = ...;

try (JsonParser parser = Yaml.createParser(reader)) {
    // Read YAML via the JsonParser
}

module-info.java:

module your.module {

    // ...
    requires io.xlate.yamljson;

    // One of the following (if not using the --add-modules java option)
    requires org.snakeyaml.engine.v2;
    requires org.yaml.snakeyaml;

}

Versions

This library is built for multiple combinations of JSON API and Yaml versions.

Supported JSON API Dependencies

Pick one of the two listed by choosing a dependency.

Jakarta JSON (module jakarta.json):

<dependency>
  <groupId>io.xlate</groupId>
  <artifactId>yaml-json</artifactId>
  <version>${version.yaml-json.current}</version>
</dependency>

Legacy Java EE JSON (module java.json):

<dependency>
  <groupId>io.xlate</groupId>
  <artifactId>yaml-json</artifactId>
  <version>${version.yaml-json.current}</version>
  <classifier>legacy</classifier>
</dependency>

Supported YAML Services

Placing one of the two supported YAML libraries on the class/module path will enable that library within yaml-json. Note, when using JPMS modules, you must also add the module via the java command or your application's module-info.java file.

If both libraries are present in your application, you can specify which to use by creating one of the factories in the io.xlate.yamljson.Yaml class and passing a configuration property with key io.xlate.yamljson.Yaml.Settings.YAML_VERSION and one of the values io.xlate.yamljson.Yaml.Versions.V1_1 or io.xlate.yamljson.Yaml.Versions.V1_2. Note, the values specified here are the names of constants, NOT the values themselves.

SnakeYaml (YAML 1.1):

<dependency>
  <groupId>org.yaml</groupId>
  <artifactId>snakeyaml</artifactId>
  <version>${version.snakeyaml}</version>
</dependency>

Note: If using JPMS, also include org.yaml.snakeyaml as required in module-info or add to java command: --add-modules=org.yaml.snakeyaml

SnakeYaml Engine (YAML 1.2):

<dependency>
  <groupId>org.snakeyaml</groupId>
  <artifactId>snakeyaml-engine</artifactId>
  <version>${version.snakeyaml-engine}</version>
</dependency>

Note: If using JPMS, also include org.snakeyaml.engine.v2 as required in module-info or add to java command: --add-modules=org.snakeyaml.engine.v2