源码
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 ;
}