【发布时间】:2017-02-18 16:30:38
【问题描述】:
在Java8之前,我们使用ObjectMapper来设置DateFormat如下
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
ObjectMapper mapper = <SomeInstantiation>
mapper.setDateFormat(df);
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
现在我们有了 java.time.format.DateTimeFormatter,它是线程安全的,并且与 SimpleDateFormat 不同,它更健壮。我想替换 ObjectMapper 上的上述设置。
如何使用 ObjectMapper 设置 DateTimeFormatter
【问题讨论】:
-
根据我收集的信息,您可以使用“配置覆盖”来做类似的事情。见the 2.8 patchnote 和this github issue。
标签: java objectmapper