在 SpringBoot中进行配置Jackson
配置文件整合
spring:jackson:date-format: yyyy-MM-dd HH:mm:ss #日期格式化#序列化相关配置serialization:indent-output: true #格式化输出fail-on-empty-beans: true #忽略无法转换的对象#反序列化相关配置deserialization:fail-on-unknown-properties: true #忽略不存在的属性default-property-inclusion: non_empty #配置空值序列化parser:allow-unquoted-control-chars: true #允许特殊符号和转义字符allow-single-quotes: true #允许单引号
配置类整合
在使用配置类时,需要注意以下几点
- 需要ConditionalOnMissingBean注解避免冲突,另外还给实例指定了名称customizeObjectMapper,
- 如果应用中通过Autowired使用此实例,需要指定这个名字,避免报错”There is more than one bean of ‘ObjectMapper ’ type”:
