反序列化“祖鲁语”在杰克逊的ISO8601格式的时间 [英] Deserialize "Zulu" time in ISO8601 format in jackson
本文介绍了反序列化“祖鲁语”在杰克逊的ISO8601格式的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要使用Jackson将格式时间 2016-11-28T10:34:25.097Z 反序列化为Java8的ZonedDateTime。
I have a need to de-serialize time of format 2016-11-28T10:34:25.097Z using Jackson into ZonedDateTime of Java8.
我相信我正确配置了ObjectMapper(工厂方法):
I believe I correctly configured ObjectMapper (a factory method):
@Bean
ObjectMapper getObjectMapper() {
ObjectMapper objectMapper = new ObjectMapper();
// some other config...
objectMapper.registerModule(new JavaTimeModule());
return objectMapper;
}
我在DTO的代码中有一个字段
And I have in my code for DTO a field
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSZ")
private ZonedDateTime updatedAt;
当我尝试解析杰克逊时,我得到了
when I try to parse this by Jackson, I get
java.lang.IllegalArgumentException: Can not deserialize value of type java.time.ZonedDateTime
from String "2016-11-28T10:34:25.097Z": Text '2016-11-28T10:34:25.097Z' could not be parsed,
unparsed text found at index 23 at [Source: N/A; line: -1, column: -1]
没有@JsonFormat问题仍然存在。
Without @JsonFormat problem remains.
我怎么可能克服这个?
推荐答案
问题可能在于'Z'在模式中。它不允许在日期时间值中使用文字Z。请尝试'X'。
The problem is probably with 'Z' in the pattern. It does not allow literal 'Z' in the date time value. Try 'X' instead.
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSX")
这篇关于反序列化“祖鲁语”在杰克逊的ISO8601格式的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文