java - 使用 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.
当我反序列化它时,description
在我的 Java 对象中看起来像这样:
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."
如您所见,它保留了新行,但不保留每行中的尾随空格。这就是我的杰克逊映射器的配置方式:
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);
有什么方法可以将它配置为在每行中也包含缩进?
解决方案
推荐阅读
- elasticsearch - 如何在elasticsearch上为对象制作映射
- elasticsearch - 是否可以将 MultiGet 与弹性搜索中的 Bool 查询结合使用?
- excel - Powershell:Excel数据读取问题
- java - Java Flight Recorder - 查找文件描述符泄漏
- terraform - terraform statefile 已锁定如何解锁
- html5-video - 可以通过操作 bufferBehind 来增加 Shaka 中的搜索范围吗?
- spring-boot - 基于 Okta Group 的 Spring Security Role
- c - 为什么我的客户端-服务器解决方案的服务器会立即关闭连接?
- git - SVN 到 Git 迁移 - 使用一个主干处理多个项目
- arduino - 尝试使用 Arduino 在 ESP8266 上使用未知协议从遥控器复制 IR 信号