【发布时间】:2018-03-13 14:33:48
【问题描述】:
我正在使用Jackson 将对象序列化为 YAML(jackson-dataformat-yaml 库)。
我想为标量值(例如以下示例中的“描述”)生成literal style 输出,例如
---
id: 4711
description: |
FooBar
HelloWorld
但我只能生成这样的带引号的标量:
---
id: 4711
description: "FooBar\nHelloWorld"
我用来生成 ObjectMapper 的代码(到目前为止)非常简单:
YAMLFactory f = new YAMLFactory();
f.enable(YAMLGenerator.Feature.SPLIT_LINES); // setting does not matter
ObjectMapper objectMapperYaml = new ObjectMapper(f);
String yaml = objectMapperYaml.writeValueAsString(someObject);
我猜有可能生成文字样式的标量值,但我不知道如何。欢迎任何提示!
【问题讨论】: