我使用 SnakeYAML 将数据保存到 YAML 文件中。
DumperOptions options = new DumperOptions();
options.setPrettyFlow(true);
options.setAllowReadOnlyProperties(true);
Yaml yml = new Yaml(options);
FileWriter writer = new FileWriter(path);
yml.dump(object, writer);
writer.flush();
writer.close();
当我尝试保存结果时,我得到了这样的内容
!!com.test.yml.User
users:
- {
name: Bob,
age: 14
}
- {
name: John,
age: 15
}
如何避免!!com.test.yml.User
文件中的类?
我也不想保存空实体。例如
- {
name: null,
age: 14
}
应该
- {
age: 14
}