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) {