时间戳序列化问题

This commit is contained in:
wangliwen 2022-05-13 09:35:49 +08:00
parent 9e155eaf73
commit 10899efa6c
1 changed files with 11 additions and 3 deletions

View File

@ -1,7 +1,6 @@
package io.renren.modules.resource.listener;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.*;
import io.renren.modules.resource.dto.ResourceDTO;
import io.renren.modules.resource.entity.ResourceEntityDelFlag;
import io.renren.modules.resource.service.ResourceService;
@ -22,6 +21,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.lang.reflect.Type;
import java.util.Date;
import java.util.Map;
@ -87,7 +88,14 @@ public class ResourceUndercarriageListener implements TaskListener, ExecutionLis
* @param kv
*/
private void endTake(Map<String, Object> kv) { // 进入最后结束节点
Gson gson = new Gson();
GsonBuilder builder = new GsonBuilder();
builder.registerTypeAdapter(Date.class, new JsonDeserializer<Date>() {
public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
return new Date(json.getAsJsonPrimitive().getAsLong());
}
});
Gson gson = builder.create();
JsonElement jsonElement = gson.toJsonTree(kv);
ResourceDTO re = gson.fromJson(jsonElement, ResourceDTO.class);
if (re != null) {