import java.io.File;
import java.io.IOException;
import org.yaml.snakeyaml.Yaml;
public class YamlExample {
public static void main(String[] args) {
try {
Yaml yaml = new Yaml();
File file = new File("example.yaml");
Object data = yaml.load(file);
System.out.println(data);
} catch (IOException e) {
e.printStackTrace();
}
try {
Yaml yaml = new Yaml();
Person person = new Person("John Doe", 30);
String yamlString = yaml.dump(person);
System.out.println(yamlString);
} catch (IOException e) {
e.printStackTrace();
}
}
}
class Person {
private String name;
private int age;
public Person(String name, int age) {
this.name = name;
this.age = age;
}
}