如何在Spring Boot Jackson Date序列化中应用默认时区 [英] How to make default time zone apply in Spring Boot Jackson Date serialization
本文介绍了如何在Spring Boot Jackson Date序列化中应用默认时区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已将Spring Boot应用程序配置为将日期序列化为ISO8601字符串:
I have configured my Spring Boot application to serialize dates as ISO8601 strings:
spring:
jackson:
serialization:
write-dates-as-timestamps: false
这是什么我得到:
"someDate": "2017-09-11T07:53:27.000+0000"
但我的时区是欧洲/马德里。事实上,如果我打印 TimeZone.getDefault()
这就是我得到的。
However my time zone is Europe/Madrid. In fact if I print TimeZone.getDefault()
that's what I get.
如何让Jackson序列化那些使用实际时区的日期时间值? GMT + 2
How can I make Jackson serialize those datetime values using the actual timezone? GMT+2
"someDate": "2017-09-11T09:53:27.000+0200"
推荐答案
解决了注册Jackson2ObjectMapperBuilderCustomizer bean的问题:
Solved registering a Jackson2ObjectMapperBuilderCustomizer bean:
@Bean
public Jackson2ObjectMapperBuilderCustomizer jacksonObjectMapperCustomization() {
return jacksonObjectMapperBuilder ->
jacksonObjectMapperBuilder.timeZone(TimeZone.getDefault());
}
这篇关于如何在Spring Boot Jackson Date序列化中应用默认时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文