我有yaml
文件,我是通过Java创建的。
--- !!com.test.users.Configuration
config:
userList: !!set
? name: John
age: 18
: null
? name: Axel
age: 14
: null
defaultUser:
name: Bob
age: 15
这是我的SnakeYML代码
DumperOptions options = new DumperOptions();
options.setDefaultScalarStyle(DumperOptions.ScalarStyle.PLAIN);
options.setPrettyFlow(true);
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
options.setAllowReadOnlyProperties(true);
options.setExplicitStart(true);
yml = new Yaml(options);
FileWriter writer = new FileWriter(path);
yml.dump(obj, writer);
问题是如何排除所有这些多余的!!noise
com.test.users.Configuration
,?
,: null
,!!set
?
答案 0 :(得分:0)
1)
Representer representer = new Representer();
representer.addClassTag(com.test.users.Configuration.class, Tag.MAP);
Yaml yaml = new Yaml(representer);
2)使用List而不是设置以避免!!set
和:null