高德完单、取消订单接口
This commit is contained in:
parent
29a68432e8
commit
cf3239e6bb
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
package com.chint.interfaces.rest.base;
|
package com.chint.interfaces.rest.base;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.chint.infrastructure.util.LocalDateTimeAdapter;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.google.common.base.Charsets;
|
import com.google.common.base.Charsets;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.GsonBuilder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.http.Header;
|
import org.apache.http.Header;
|
||||||
|
@ -32,6 +34,7 @@ import java.lang.reflect.Method;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import static com.chint.infrastructure.constant.CommonMessageConstant.REDIRECT_NOT_EXIST;
|
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) {
|
public <T> T postANBPM(String url, Object jsonRequest, Class<T> responseType) {
|
||||||
HttpPost post = new HttpPost(url);
|
HttpPost post = new HttpPost(url);
|
||||||
|
Gson gson = new GsonBuilder().registerTypeAdapter(LocalDateTime.class, new LocalDateTimeAdapter()).create();//能够正常序列化对象的LocalDateTime字段
|
||||||
String json = gson.toJson(jsonRequest);
|
String json = gson.toJson(jsonRequest);
|
||||||
log.info(json);
|
log.info(json);
|
||||||
post.setEntity(new StringEntity(json, ContentType.APPLICATION_JSON));
|
post.setEntity(new StringEntity(json, ContentType.APPLICATION_JSON));
|
||||||
|
|
Loading…
Reference in New Issue