Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/devatherock/simple-yaml

A simple YAML generator for Java
https://github.com/devatherock/simple-yaml

java yaml yaml-generator

Last synced: 2 months ago
JSON representation

A simple YAML generator for Java

Awesome Lists containing this project

README

        

[![CircleCI](https://img.shields.io/circleci/project/github/devatherock/simple-yaml/master.svg)](https://circleci.com/gh/devatherock/simple-yaml)
[![Download](https://img.shields.io/maven-central/v/io.github.devatherock/simple-yaml)](https://mvnrepository.com/artifact/io.github.devatherock/simple-yaml)
[![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=simple-yaml&metric=ncloc)](https://sonarcloud.io/dashboard?id=simple-yaml)
[![Coverage Status](https://coveralls.io/repos/github/devatherock/simple-yaml/badge.svg?branch=master)](https://coveralls.io/github/devatherock/simple-yaml?branch=master)
[![Quality Gate](https://sonarcloud.io/api/project_badges/measure?project=simple-yaml&metric=alert_status)](https://sonarcloud.io/component_measures?id=simple-yaml&metric=alert_status&view=list)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
# simple-yaml
A simple YAML generator for Java

## Usage

For Gradle:
```groovy
dependencies {
implementation group: 'io.github.devatherock', name: 'simple-yaml', version: '0.3.0'
}
```

For Maven:
```xml


io.github.devatherock
simple-yaml
0.3.0

```

### Generating YAML
#### With default settings
```java
Map map = new HashMap<>();
map.put("foo", "bar");
map.put("version", "1");
map.put("colors", Arrays.asList("red", "blue"));
String output = SimpleYamlOutput.toYaml(map);
```

Output:
```yaml
foo: bar
version: 1
colors:
- red
- blue
```

#### With custom settings
```java
Map map = new HashMap<>();
map.put("foo", "bar");
map.put("version", "1");
map.put("colors", Arrays.asList("red", "blue"));
SimpleYamlOutput yaml = SimpleYamlOutput.builder()
.numericFieldToQuote("version")
.flowStyleArrayField("colors")
.indentArrays(false)
.indentSize(3)
.quoteType(SimpleYamlOutput.QuoteType.SINGLE)
.build();
String output = yaml.dump(map);
```

Output:
```yaml
foo: bar
version: '1'
colors: [ red, blue ]
```