Feign远程调用响应结果格式
public class Result<T> {
private Integer code;
private String message;
private T data;
}
自定义Feign解码器
@Component
public class FeignResultDecoder implements Decoder {
@Override
public Object decode(Response response, Type type) throws IOException, DecodeException, FeignException {
if (response.body() == null) {
throw new DecodeException(response.status(), "未返回正确的数据", response.request());
}
String bodyStr = Util.toString(response.body().asReader(Util.UTF_8));
Result result = (Result) JsonUtil.json2obj(bodyStr, type);
return result.data;
}
}