You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "lcinshu (GitHub)" <gi...@apache.org> on 2020/02/14 14:26:56 UTC

[GitHub] [dubbo] lcinshu commented on issue #5342: Hutool DateTime Value is changed current time

#### 环境
dubbo version:2.5.3
os:mac os
jdk:1.8
我也遇到了类似问题,看了下dubbo和hutool相关源码
#### 简要分析下原因:
1. DateTime是hutool组件自定义的类,继承自Date,底层还是依赖Date类型存储时间,在序列化时使用自定义序列化器(JavaSerializer和JavaDeserializer),Date父类中的字段均为static或transient,因此不会被序列化
2. 反序列化的时候,调用DateTime默认构造方法,赋值为当前时间,由于没有序列化date相关字段,所以反序列化时也不会获取到date类型的值
![image](https://user-images.githubusercontent.com/17569008/74516394-452dea80-4f4b-11ea-9b2f-1c733b804bfb.png)

#### 解决办法
思路:转成Date类型,简单直接
DateTime考虑到各种框架之间兼容性问题,提供了toJdkDate()方法,可以转成Date类型,这样序列化就没问题了

#### 验证
![image](https://user-images.githubusercontent.com/17569008/74517881-ec138600-4f4d-11ea-931a-c4f9a029b998.png)
![image](https://user-images.githubusercontent.com/17569008/74517904-f6ce1b00-4f4d-11ea-83fb-8c89f10313c7.png)





[ Full content available at: https://github.com/apache/dubbo/issues/5342 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org