From 10899efa6c60f30455ccd8c4b70ca09fd8060fca Mon Sep 17 00:00:00 2001 From: wangliwen Date: Fri, 13 May 2022 09:35:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=B6=E9=97=B4=E6=88=B3=E5=BA=8F=E5=88=97?= =?UTF-8?q?=E5=8C=96=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../listener/ResourceUndercarriageListener.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/renren-admin/src/main/java/io/renren/modules/resource/listener/ResourceUndercarriageListener.java b/renren-admin/src/main/java/io/renren/modules/resource/listener/ResourceUndercarriageListener.java index ec59eb10..d611bbfb 100644 --- a/renren-admin/src/main/java/io/renren/modules/resource/listener/ResourceUndercarriageListener.java +++ b/renren-admin/src/main/java/io/renren/modules/resource/listener/ResourceUndercarriageListener.java @@ -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 kv) { // 进入最后结束节点 - Gson gson = new Gson(); + GsonBuilder builder = new GsonBuilder(); + builder.registerTypeAdapter(Date.class, new JsonDeserializer() { + 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) {