源码
org.springframework.cloud.openfeign.support.SpringDecoder
public Object decode (final Response response, Type type)
throws IOException, FeignException {
if (type instanceof Class || type instanceof ParameterizedType
|| type instanceof WildcardType) {
@SuppressWarnings({ "unchecked", "rawtypes" })
HttpMessageConverterExtractor<?> extractor = new HttpMessageConverterExtractor (
type, this .messageConverters.getObject().getConverters());
return extractor.extractData(new FeignResponseAdapter (response));
}
throw new DecodeException (response.status(),
"type is not an instance of Class or ParameterizedType: " + type,
response.request());
}
org.springframework.web.client.HttpMessageConverterExtractor
public T extractData (ClientHttpResponse response) throws IOException {
MessageBodyClientHttpResponseWrapper responseWrapper = new MessageBodyClientHttpResponseWrapper (response);
if (!responseWrapper.hasMessageBody() || responseWrapper.hasEmptyMessageBody()) {
return null ;
}
MediaType contentType = getContentType(responseWrapper);
try {
for (HttpMessageConverter<?> messageConverter : this .messageConverters) {
if (messageConverter instanceof GenericHttpMessageConverter) {
GenericHttpMessageConverter<?> genericMessageConverter =
(GenericHttpMessageConverter<?>) messageConverter;
if (genericMessageConverter.canRead(this .responseType, null , contentType)) {
if (logger.isDebugEnabled()) {
ResolvableType resolvableType = ResolvableType.forType(this .responseType);
logger.debug("Reading to [" + resolvableType + "]" );
}
return (T) genericMessageConverter.read(this .responseType, null , responseWrapper);
}
}
if (this .responseClass != null ) {
if (messageConverter.canRead(this .responseClass, contentType)) {
if (logger.isDebugEnabled()) {
String className = this .responseClass.getName();
logger.debug("Reading to [" + className + "] as \"" + contentType + "\"" );
}
return (T) messageConverter.read((Class) this .responseClass, responseWrapper);
}
}
}
}
catch (IOException | HttpMessageNotReadableException ex) {
throw new RestClientException ("Error while extracting response for type [" +
this .responseType + "] and content type [" + contentType + "]" , ex);
}
throw new RestClientException ("Could not extract response: no suitable HttpMessageConverter found " +
"for response type [" + this .responseType + "] and content type [" + contentType + "]" );
}
org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter
public boolean canRead (Type type, @Nullable Class<?> contextClass, @Nullable MediaType mediaType) {
if (!canRead(mediaType)) {
return false ;
}
JavaType javaType = getJavaType(type, contextClass);
AtomicReference<Throwable> causeRef = new AtomicReference <>();
if (this .objectMapper.canDeserialize(javaType, causeRef)) {
return true ;
}
logWarningIfNecessary(javaType, causeRef.get());
return false ;
}
com.fasterxml.jackson.databind.DeserializationContext
public boolean hasValueDeserializerFor (JavaType type, AtomicReference<Throwable> cause) {
try {
return _cache.hasValueDeserializerFor(this , _factory, type);
} catch (JsonMappingException e) {
if (cause != null ) {
cause.set(e);
}
} catch (RuntimeException e) {
if (cause == null ) {
throw e;
}
cause.set(e);
}
return false ;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?