【发布时间】:2019-06-09 02:52:34
【问题描述】:
我只需要将 Java 字符串 description,instructions 解析为 yaml 中的文字块 (|),因为上述两个变量都可以包含多行输入并将 infoId 解析为通常的字符串。我使用 snakeyaml 作为 yaml 库。我如何实现上述目标?我需要为此使用任何注释吗?
Pojo 类
public class Info {
private String infoId;
private String description;
private String instructions;
// Setters and getters
}
解析类
...
Info info = new Info();
info.setDescription(descriptionWithMultilines);
info.setIntructions(instructionsWithMultilines);
Yaml yaml = new Yaml();
String yamlString = yaml.dumpAs(info, Tag.MAP, DumperOptions.FlowStyle.BLOCK);
...
【问题讨论】:
-
您能否添加一个示例,您希望输出是什么样的。
标签: java parsing annotations yaml snakeyaml