Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/HituziANDO/YAMLParserJava
YAML decoder in Java.
https://github.com/HituziANDO/YAMLParserJava
decoder java parser yaml
Last synced: 3 months ago
JSON representation
YAML decoder in Java.
- Host: GitHub
- URL: https://github.com/HituziANDO/YAMLParserJava
- Owner: HituziANDO
- License: mit
- Created: 2014-07-01T15:30:24.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2019-01-04T16:23:51.000Z (about 6 years ago)
- Last Synced: 2024-07-30T21:06:49.775Z (5 months ago)
- Topics: decoder, java, parser, yaml
- Language: Java
- Homepage:
- Size: 14.6 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# YAMLParserJava
***YAML decoder in Java.***
## Include in your project
1. Puts `src/HashTypeYaml.java` in your project
1. Sets any package to HashTypeYaml.java## Usage
For example, decodes following YAML as test1.yml file.
```yaml
test1:
id: 1234
country: "Japan"
code:
data:
users:
- Alice
- Bob
- Chris
title: "ABC Team"
description: "ABC Team is the best!"
```1. Create instance
```java
HashTypeYaml yaml = new HashTypeYaml();
```1. Decode YAML and convert to Map object
```java
try {
Map map = yaml.decode(new FileInputStream("test1.yml"));
} catch (IOException e) {
// Error handling
}
```
Or
```java
Map map = yaml.decodeOrEmpty("test1.yml");
```
`decodeOrEmpty` does not raise the exception and returns empty map if I/O error is occurred.1. Get value
```java
// Get id.
System.out.println(map.get("test1/id")); // => 1234
// Get title.
System.out.println(map.get("test1/data/title")); // => ABC Team
// Get users.
List users = (List) map.get("test1/data/users");
System.out.println(users.get(1)); // => Bob
```More info, see my [sample code](https://github.com/HituziANDO/YAMLParserJava/blob/master/src/Main.java).