Yaml to java bean

  java

Yaml format

name: demo
desc: this is desc
items:
    - name: item
      desc: item desc
    - name: item2
      desc: desc2

maven

<dependency>
            <groupId>com.github.sanjusoftware</groupId>
            <artifactId>yamlbeans</artifactId>
            <version>1.11</version>
        </dependency>

bean

public class Demo{
    private String name;
    private String desc;
    private List<Demo> items;
    
    //getter setter
}

Conversion

        ClassLoader classLoader = getClass().getClassLoader();
        String path = classLoader.getResource("demo.yaml").getPath();
        YamlReader reader = new YamlReader(new FileReader(path));
        Demo demo = reader.read(Demo.class);

doc