如何设置Java-SnakeYaml Dumperoptions以省去引号和'|';?

如何设置Java-SnakeYaml Dumperoptions以省去引号和'|';?,java,yaml,snakeyaml,Java,Yaml,Snakeyaml,我使用Java中的Snakeyaml转储Yaml文件,该文件稍后由另一个应用程序解析 输出Yaml必须如下所示: aKey: 1234 anotherKey: a string thirdKey: 4321: - some script code passed as a string - a second line of code passed as a string DumperOptions options = new DumperOptions(); options.

我使用Java中的Snakeyaml转储Yaml文件,该文件稍后由另一个应用程序解析

输出Yaml必须如下所示:

aKey: 1234
anotherKey: a string
thirdKey:
  4321:
    - some script code passed as a string
    - a second line of code passed as a string
DumperOptions options = new DumperOptions();
options.setIndent(2);
options.setPrettyFlow(true);
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
[...]
Map<String, Object> data = new LinkedHashMap<>();
Map<Integer, Object> thirdKey= new LinkedHashMap<>();
data.put("aKey", 1234);
data.put("anotherKey", "aString");
StringBuilder extended = new StringBuilder();
extended.append("- some script code passed as a string\n- a second line of code passed as a string\n");
String result = extended.toString();
thirdKey.put(4321, result);
data.put("thirdKey", thirdKey);
yaml.dump(data, writer);
aKey: 1234
anotherKey: a string
thirdKey:
  4321: |
    - some script code passed as a string
    - a second line of code passed as a string
到目前为止,我最接近的方法是设置转储程序选项,如下所示:

aKey: 1234
anotherKey: a string
thirdKey:
  4321:
    - some script code passed as a string
    - a second line of code passed as a string
DumperOptions options = new DumperOptions();
options.setIndent(2);
options.setPrettyFlow(true);
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
[...]
Map<String, Object> data = new LinkedHashMap<>();
Map<Integer, Object> thirdKey= new LinkedHashMap<>();
data.put("aKey", 1234);
data.put("anotherKey", "aString");
StringBuilder extended = new StringBuilder();
extended.append("- some script code passed as a string\n- a second line of code passed as a string\n");
String result = extended.toString();
thirdKey.put(4321, result);
data.put("thirdKey", thirdKey);
yaml.dump(data, writer);
aKey: 1234
anotherKey: a string
thirdKey:
  4321: |
    - some script code passed as a string
    - a second line of code passed as a string
仅仅是|使我无法实现我的最终目标


是否有任何方法可以设置dumperoptions,以便在不插入|符号的情况下断开行?

问题在于,您生成列表标记作为内容的一部分。他们不是!它们是YAML语法的一部分

由于YAML中需要的是一个序列(列表的YAML术语),因此必须将列表放入结构中:

thirdKey.put(4321,Arrays.asList(
“某些脚本代码作为字符串传递”,
“作为字符串传递的第二行代码”);