我有一段代码,它将LinkedHashMap转换成YAML对象
public class TestDump {
public static void main(String[] args) {
LinkedHashMap<String, Object> values = new LinkedHashMap<String, Object>();
values.put("one", 1);
values.put("two", 2);
values.put("three", 3);
DumperOptions options = new DumperOptions();
options.setIndent(2);
options.setPrettyFlow(true);
Yaml output = new Yaml(options);
File targetYAMLFile = new File("C:\\temp\\sample.yaml");
FileWriter writer =null;
try {
writer = new FileWriter(targetYAMLFile);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
output.dump(values, writer);
}
}
但是输出结果看起来像这样
{
one: 1,
two: 2,
three: 3
}
有没有办法将此设置为这样?
one: 1
two: 2
three: 3
尽管第一个是有效的yaml格式..但我希望输出格式类似于第二个。