栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

使用Jackson的json中的ISO8601毫秒

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用Jackson的json中的ISO8601毫秒

ISO8601DateFormat.format
Calls
ISO8601Utils.format(date)
,反过来又调用
format(date, false,TIMEZONE_Z)
-
false
参数告诉Jackson不包括毫秒。

似乎没有办法配置此类或设置任何参数,但是幸运的是可以对其进行扩展:

public class ISO8601WithMillisFormat extends ISO8601DateFormat {    @Override    public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) {        String value = ISO8601Utils.format(date, true); // "true" to include milliseconds        toAppendTo.append(value);        return toAppendTo;    }}

然后,我们可以在对象映射器中使用这个新类:

ObjectMapper objectMapper = new ObjectMapper();ISO8601DateFormat dateFormat = new ISO8601WithMillisFormat();objectMapper.setDateFormat(dateFormat);

我进行了测试,

new Date()
结果为
2017-07-24T12:14:26.817Z
(毫秒)。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/398151.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号