SnakeYAML 格式 - 删除 YAML 大括号

SnakeYAML formatting - remove YAML curly brackets

我有一个代码将 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..我希望输出格式与第二个一样。

看起来这只是通过 DumperOptions:

进行的一些配置
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);
        // Fix below - additional configuration
        options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
        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);
    }
}

这将解决我的问题