高德完单、取消订单接口

This commit is contained in:
dengwc 2024-04-17 15:01:59 +08:00
parent 29a68432e8
commit cf3239e6bb
2 changed files with 29 additions and 0 deletions

View File

@ -0,0 +1,25 @@
package com.chint.infrastructure.util;
import com.google.gson.*;
import java.lang.reflect.Type;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
/**
* GSON序列化LocalDateTime适配器
*/
public class LocalDateTimeAdapter implements JsonSerializer<LocalDateTime>, JsonDeserializer<LocalDateTime> {
private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS");
@Override
public JsonElement serialize(LocalDateTime src, Type typeOfSrc, JsonSerializationContext context) {
return new JsonPrimitive(formatter.format(src));
}
@Override
public LocalDateTime deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
return LocalDateTime.parse(json.getAsString(), formatter);
}
}

View File

@ -1,10 +1,12 @@
package com.chint.interfaces.rest.base;
import com.alibaba.fastjson.JSON;
import com.chint.infrastructure.util.LocalDateTimeAdapter;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Charsets;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.Header;
@ -32,6 +34,7 @@ import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.URLEncoder;
import java.time.LocalDateTime;
import java.util.*;
import static com.chint.infrastructure.constant.CommonMessageConstant.REDIRECT_NOT_EXIST;
@ -181,6 +184,7 @@ public class PostRequest {
public <T> T postANBPM(String url, Object jsonRequest, Class<T> responseType) {
HttpPost post = new HttpPost(url);
Gson gson = new GsonBuilder().registerTypeAdapter(LocalDateTime.class, new LocalDateTimeAdapter()).create();//能够正常序列化对象的LocalDateTime字段
String json = gson.toJson(jsonRequest);
log.info(json);
post.setEntity(new StringEntity(json, ContentType.APPLICATION_JSON));