2
snakeyaml
lib로 Yaml 파일을 구문 분석하려고합니다. 여기 내 yaml 파일이 있습니다.Yaml : 컬렉션을 deserialize하는 방법?
---
users:
- name: Bobby
status: single
license: no
- name: Timmy
status: single
license: no
available: yes
Java 코드.
public class Users {
private List<User> users;
// getters/setters/def constructor have omitted
}
사용자 등급.
public class User {
private String name;
private String status;
private String license;
private String available;
// getters/setters/def constructor have omitted
}
콘텐츠를 파싱하기위한 내 코드.
Constructor constructor = new Constructor(Users.class);
TypeDescription usersDescription = new TypeDescription(Users.class);
profileDescription.putListPropertyType("users", User.class);
constructor.addTypeDescription(usersDescription);
Yaml yml = new Yaml(constructor);
Users users = (Users) yml.load(new FileInputStream(new File("/path/file.yaml")));
하지만 예외가 있습니다.
Exception in thread "main" Cannot create property=users for JavaBean=Users(users=null)
in 'reader', line 1, column 1:
users:
^
어떻게 해결할 수 있습니까?
PS
나는이 사용자와 컨텐츠를 덤프하려고 나는
!!com.project.model.Users
users:
- {}
- {}