java.util.Date 序列化与反序列化(用时间戳表示,精确到秒)
参考DateCodec实现一个自定义类,改写其中write与cast方法
-
out.writeLong(time / 1000);
-
-
//---------------------------
-
-
long value = ((Number) val).longValue() * 1000;
-
return (T) new java.util.Date(value);
-
-
long value = Long.parseLong(strVal) * 1000;
-
return (T) new java.util.Date(value);
全局配置:
-
SerializeConfig.getGlobalInstance().put(Date.class, MyDateCodec.instance);
-
ParserConfig.getGlobalInstance().putDeserializer(Date.class, MyDateCodec.instance);
参考:
-
https://github.com/alibaba/fastjson/wiki
-
-
https://github.com/alibaba/fastjson/wiki/Class_Level_SerializeFilter
-
-
https://github.com/alibaba/fastjson/wiki/SerializeFilter
-
-
https://github.com/alibaba/fastjson/wiki/ParseProcess
阅读(1974) | 评论(0) | 转发(0) |