import org.yaml.snakeyaml.Yaml;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
public class YamlParser {
public static void main(String[] args) {
try {
Yaml yaml = new Yaml();
FileInputStream inputStream = new FileInputStream("example.yaml");
Object data = yaml.load(inputStream);
System.out.println(data.toString());
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
1. Jackson
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import java.io.File;
import java.io.IOException;
public class YamlParser {
public static void main(String[] args) {
try {
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
File file = new File("example.yaml");
Object data = mapper.readValue(file, Object.class);
System.out.println(data.toString());
} catch (IOException e) {
e.printStackTrace();
}
}
}
2. SnakeYAML
import org.yaml.snakeyaml.Yaml;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
public class YamlParser {
public static void main(String[] args) {
try {
Yaml yaml = new Yaml();
FileInputStream inputStream = new FileInputStream("example.yaml");
Object data = yaml.load(inputStream);
System.out.println(data.toString());
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
3. YamlBeans
import com.esotericsoftware.yamlbeans.YamlReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
public class YamlParser {
public static void main(String[] args) {
try {
YamlReader reader = new YamlReader(new FileReader("example.yaml"));
Object data = reader.read();
System.out.println(data.toString());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
}