【发布时间】:2020-06-12 13:41:37
【问题描述】:
我正在使用带有以下 ObjectMapper 的 Spring Boot:
@Bean
public ObjectMapper objectMapper()
{
final ObjectMapper mapper = new ObjectMapper();
mapper.enable(SerializationFeature.INDENT_OUTPUT);
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
mapper.setDateFormat(new StdDateFormat().withColonInTimeZone(true)); // Makes no difference to output
mapper.findAndRegisterModules();
return mapper;
}
当 OffsetDateTimes 被序列化并在响应中返回时,它们的格式如下:
"2020-02-28T12:28:29.01Z"
"2020-02-28T12:36:21.885Z"
我本来希望最后的时区信息看起来像这样:
"2020-02-28T10:41:25.287+00:00"
我在这里有什么遗漏或做错了吗,或者无论如何我可以将时区信息序列化为+00:00 格式而不是885Z 格式?
非常感谢!
【问题讨论】:
-
它确实包括了时区,只是不是你所期望的。 'Z' 代表祖鲁时间,类似于 +00:00