|
@@ -1,35 +0,0 @@
|
|
|
-package com.ydd.config;
|
|
|
-
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
-import feign.FeignException;
|
|
|
-import feign.Response;
|
|
|
-import feign.Util;
|
|
|
-import feign.codec.DecodeException;
|
|
|
-import feign.codec.Decoder;
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
-import sun.reflect.generics.reflectiveObjects.TypeVariableImpl;
|
|
|
-
|
|
|
-import java.io.IOException;
|
|
|
-import java.lang.reflect.Method;
|
|
|
-import java.lang.reflect.Type;
|
|
|
-
|
|
|
-/**
|
|
|
- * @author 叶君翔
|
|
|
- * @date 2022/04/19 15:44
|
|
|
- */
|
|
|
-@Slf4j
|
|
|
-public class GenericsFeignResultDecoder implements Decoder {
|
|
|
-
|
|
|
- @Override
|
|
|
- public Object decode(Response response, Type type) throws IOException, DecodeException, FeignException {
|
|
|
- if (response.body() == null) {
|
|
|
- throw new DecodeException(response.status(), "no data response", response.request());
|
|
|
- }
|
|
|
- Class returnType = ((Method)((TypeVariableImpl)type).getGenericDeclaration()).getReturnType();
|
|
|
- String bodyStr = Util.toString(response.body().asReader(Util.UTF_8));
|
|
|
- log.info("bodyStr==================={}", bodyStr);
|
|
|
- //对结果进行转换
|
|
|
- return JSON.parseObject(bodyStr,returnType);
|
|
|
- }
|
|
|
-
|
|
|
-}
|