java使用snakeyaml操作yaml文件进行序列化和反序列化,网上很多案例,load和dump的使用不再重复说,只说我遇到的一些情况。
我在使用dump生成yaml文件时候在第一行总是出现!!,classtype是类型名称,便于load加载生成对象时候做校验,但是我不需要这个,解决如下:
使用 dumpAsMap 就可以了。第一行不再出现!!类型说明。
Yaml yaml = new Yaml(); String result = yaml.dumpAsMap(object);
源码: dumpAsMap 将tag设置成了map: Tag.MAP