gson 时间戳问题

This commit is contained in:
wangliwen 2022-05-13 10:23:20 +08:00
parent d34303b92f
commit 1cce4f9888
5 changed files with 73 additions and 15 deletions

View File

@ -115,7 +115,6 @@ public class DemandDataListener implements TaskListener, ExecutionListener, Acti
});
Gson gson = builder.create();
// Gson gson = new Gson();
JsonElement jsonElement = gson.toJsonTree(kv);
TDemandDataDTO demandDataDTO = gson.fromJson(jsonElement, TDemandDataDTO.class);

View File

@ -1,7 +1,6 @@
package io.renren.modules.processForm.listener;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.*;
import io.renren.modules.activiti.service.ActTaskService;
import io.renren.modules.processForm.dto.TAbilityApplicationDTO;
import io.renren.modules.processForm.service.ApiGatewayService;
@ -27,6 +26,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;
import java.util.Optional;
import java.util.UUID;
@ -112,7 +113,14 @@ public class CorrectionListener implements TaskListener, ExecutionListener, Acti
* @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);
TAbilityApplicationDTO abilityApplicationDTO = gson.fromJson(jsonElement, TAbilityApplicationDTO.class);
if (abilityApplicationDTO != null) {
@ -130,7 +138,14 @@ public class CorrectionListener implements TaskListener, ExecutionListener, Acti
*/
private void create(DelegateTask delegateTask) {
Map<String, Object> kv = delegateTask.getVariables();
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);
TAbilityApplicationDTO abilityApplicationDTO = gson.fromJson(jsonElement, TAbilityApplicationDTO.class);
@ -196,7 +211,14 @@ public class CorrectionListener implements TaskListener, ExecutionListener, Acti
if (kv.get("gatewayCode") != null ||
!ActTaskService.Task_HANDLE_STATE_AGREE.equals(kv.get(ActTaskService.Task_HANDLE_STATE))) return;
try {
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);
TAbilityApplicationDTO abilityApplicationDTO = gson.fromJson(jsonElement, TAbilityApplicationDTO.class);
applyCode(delegateTask, abilityApplicationDTO);

View File

@ -1,7 +1,6 @@
package io.renren.modules.processForm.listener;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.*;
import io.renren.modules.processForm.dto.TAbilityApplicationDTO;
import io.renren.modules.resource.dto.ResourceDTO;
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;
import java.util.Optional;
@ -108,7 +109,14 @@ public class DataCenterListener implements TaskListener, ExecutionListener, Acti
}
Map<String, Object> kv = delegateTask.getVariables();
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);
TAbilityApplicationDTO abilityApplicationDTO = gson.fromJson(jsonElement, TAbilityApplicationDTO.class);
Optional<ResourceDTO> resourceDTOOptional = Optional.ofNullable(resourceService.get(Long.valueOf(abilityApplicationDTO.getResourceId())));

View File

@ -114,7 +114,14 @@ public class ResourceUndercarriageListener implements TaskListener, ExecutionLis
*/
private void create(DelegateTask delegateTask, final SysRoleDTO roleDTO) {
Map<String, Object> kv = delegateTask.getVariables();
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.getDeptId() != null) {

View File

@ -1,8 +1,7 @@
package io.renren.modules.resourceMountApply.listener;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.*;
import io.renren.modules.processForm.service.ApiGatewayService;
import io.renren.modules.resource.dto.ResourceDTO;
import io.renren.modules.resource.service.ResourceService;
@ -23,6 +22,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;
/**
@ -114,7 +115,14 @@ public class ResourceOwnerListener implements TaskListener, ExecutionListener, A
* @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);
TResourceMountApplyDTO resourceMountApplyDTO = gson.fromJson(jsonElement, TResourceMountApplyDTO.class);
ResourceDTO re = resourceMountApplyDTO.getResourceDTO();
@ -133,7 +141,14 @@ public class ResourceOwnerListener implements TaskListener, ExecutionListener, A
*/
private void complete(DelegateTask delegateTask) {
Map<String, Object> kv = delegateTask.getVariables();
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);
TResourceMountApplyDTO resourceMountApplyDTO = gson.fromJson(jsonElement, TResourceMountApplyDTO.class);
Long resourceID = resourceMountApplyDTO.getResourceDTO().getId();
@ -155,7 +170,14 @@ public class ResourceOwnerListener implements TaskListener, ExecutionListener, A
*/
private void create(DelegateTask delegateTask, final SysRoleDTO roleDTO) {
Map<String, Object> kv = delegateTask.getVariables();
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);
TResourceMountApplyDTO resourceMountApplyDTO = gson.fromJson(jsonElement, TResourceMountApplyDTO.class);
logger.error(JSONObject.toJSONString(resourceMountApplyDTO));