使用 Jackson 将 YAML 反序列化为 Java 对象时在新行中保留缩进

问题描述

我希望在将 YAML 反序列化为 Java 对象时能够保留缩进。如果这是我的 YAML:

description: |
  Lorem Ipsum is simply dummy text of the printing and typesetting industry. 
  Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,when an unkNown printer took a galley of 
  type and scrambled it to make a type specimen book.

当我反序列化它时,我的 Java 对象中的 description 看起来像这样:

description: "Lorem Ipsum is simply dummy text of the printing and typesetting industry.\n
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,\nwhen an unkNown printer took a galley of\ntype and scrambled it to make a type specimen book."

如您所见,它保留了新行,但不保留每行中的尾随空格。 这是我的 Jackson 映射器的配置方式:

YAMLFactory yamlFactory = new YAMLFactory()
            .disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER)
            .enable(YAMLGenerator.Feature.MINIMIZE_QUOTES)
            .enable(YAMLGenerator.Feature.INDENT_ARRAYS);
    ObjectMapper objectMapper = new ObjectMapper(yamlFactory)
            .setSerializationInclusion(JsonInclude.Include.NON_NULL);

有什么办法可以将其配置为在每一行中也包含缩进吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)