在 SpringBoot中进行配置Jackson

配置文件整合

  1. spring:
  2. jackson:
  3. date-format: yyyy-MM-dd HH:mm:ss #日期格式化
  4. #序列化相关配置
  5. serialization:
  6. indent-output: true #格式化输出
  7. fail-on-empty-beans: true #忽略无法转换的对象
  8. #反序列化相关配置
  9. deserialization:
  10. fail-on-unknown-properties: true #忽略不存在的属性
  11. default-property-inclusion: non_empty #配置空值序列化
  12. parser:
  13. allow-unquoted-control-chars: true #允许特殊符号和转义字符
  14. allow-single-quotes: true #允许单引号

配置类整合

在使用配置类时,需要注意以下几点

  • 需要ConditionalOnMissingBean注解避免冲突,另外还给实例指定了名称customizeObjectMapper,
  • 如果应用中通过Autowired使用此实例,需要指定这个名字,避免报错”There is more than one bean of ‘ObjectMapper ’ type”: