/Simple-YAML

A Java API that provides an easy-to-use way to store data using the YAML format.

Primary LanguageJavaGNU General Public License v3.0GPL-3.0

Simple YAML API

Latest version Build Status

This Java API provides an easy-to-use way to store data and provide configurations using the YAML format.

ko-fi

What is YAML?

YAML is a human-readable data-oriented serialization language.

Serialization is the process of translating data structures or object state into a format that can be stored and reconstructed later in the same or another computer environment.

You can learn more about YAML language here. Specifically, if you're interested to learn about the YAML syntax you can go to the Chapter 2 of the YAML specification.

Filename extensions: .yaml, .yml

What is Simple-YAML?

This API is a port from Bukkit configuration wrapper with some features added, so you can use this library wherever you want without Bukkit dependency.

Simplicity is added with the class YamlFile, which is an extension of YamlConfiguration, with easy use for creation, management and serialization of yaml files. This class is probably the only class you will need.

Furthermore, you can optionally save your files with comments in mind. With the original YamlConfiguration that is not possible, because if you save the file from code then all previous comments in the file will be removed. You can write your comments with a text editor as usual. In addition, not only you can preserve your comments but also with this API you can add comments programmatically to your configuration. Sounds good, right?

How to install

To use this API all you need is to download the latest Simple-Yaml.jar and put it as a dependency on your project.

Maven

If you are using Maven you do not need to download the jar. Instead, add this repository and dependency to your pom.xml:

<repositories>
    <repository>
      <id>jitpack.io</id>
      <url>https://jitpack.io</url>
    </repository>
</repositories>
Yaml + Configuration
<dependency>
    <groupId>me.carleslc.Simple-YAML</groupId>
    <artifactId>Simple-Yaml</artifactId>
    <version>1.7.2</version>
</dependency>
Configuration only
<dependency>
    <groupId>me.carleslc.Simple-YAML</groupId>
    <artifactId>Simple-Configuration</artifactId>
    <version>1.7.2</version>
</dependency>

Gradle

If you are using Gradle you do not need to download the jar. Instead, add this repository and dependency to your build file:

allprojects {
  repositories {
    maven { url 'https://jitpack.io' }
  }
}
Yaml + Configuration
dependencies {
  implementation 'me.carleslc.Simple-YAML:Simple-Yaml:1.7.2'
}
Configuration only
dependencies {
  implementation 'me.carleslc.Simple-YAML:Simple-Configuration:1.7.2'
}

How to use

The best way to learn how to use this API is through some examples.

You can find some examples to test here.

  • YamlExample: An example to create YAML files, save or delete simple values and move through the file configuration.
  • YamlCommentsExample: An example to load and save YAML files keeping comments.
  • YamlEncodingExample: A minimal example to check your encoding with Unicode characters.
  • YamlSerializationExample: An example for saving complex objects using serialization.
  • Person: An example of class for complex objects used in the previous file. Here you can see how to serialize and deserialize objects.

Example .yml files here.

For more information and methods see the Javadoc:

Dependencies

This API uses SnakeYAML, which is already included in the latest Simple-Yaml.jar, so you don't have to worry about anything more than putting up the jar as a dependency on your project.

Looking for other file type configurations?

Have a look to these repositories: