0
嗨我想学习如何使用snakeYAML。从串行化与hashMap丢失输出,YAML
我想保存一个库对象,所以我可以在我开始我的应用程序时再次加载它。 简单地说,我想存储我的图书馆书籍。互联网告诉我yaml是一个很好的方法来做到这一点。
我有下面的类:
public class Library {
private HashMap<String, List<Book>> library;
public Library() {
library = new HashMap<String, List<Book>>();
}
//getter
public HashMap<String, List<Book>> getHashMap() {
return library;
}
//setter
public void setHashMap(HashMap<String, List<Book>> library) {
this.library = library;
}
}
,现在我想用一个main方法将其序列化:
public static void main(String[] args) {
Library library = new Library();
LinkedList<Book> books = new LinkedList<Book>();
books.add(new Book("Some title", false));
books.add(new Book("Other Title", true));
library.putMany("books", books);
System.out.println(new Yaml().dump(books));
,但我只得到输出:
- !!model.Book {done: false, title: Some title}
- !!model.Book {done: true, title: Other Title}
有些东西告诉我我错过了像库它自。
当然!这样一个简单的错误!随着我关闭!谢谢! – Lurvas777 2013-03-04 14:57:41