在 springboot 项目中使用 @SpringBootApplication 会自动标记 @EnableAutoConfiguration

在接口中经常需要使用时间类型,Date ,如果想要格式化成指定格式需要在 application.yml 配置文件中配置

 

spring:
  jackson:
    date-format: yyyy-MM-dd HH:mm:ss.SSS
    time-zone: GMT+8
    defaultPropertyInclusion: non_null   #非空属性才序列化
    deserialization:
      FAIL_ON_UNKNOWN_PROPERTIES: false #未定义的key不序列化

 

AutoConfiguration 会将 ObjectMapper 注入到 spring 环境中,具体是在 JacksonAutoConfiguration 类中

springboot 项目中获取默认注入的序列化对象 ObjectMapper

 

 2 如果在 spring 环境中想要使用配置的 ObjectMapper ,使用自动注入方法即可

@Autowired
private ObjectMapper objectMapper;

 

相关文章:

  • 2022-12-23
  • 2021-09-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-13
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案