FeignClient可以解码响应

问题描述

我在春季引导中使用FeignClient。我有一些问题。

我的配置文件是:

@Configuration
@EnableFeignClients
@Import( FeignClientsConfiguration.class )
public class FeignConfiguration
{
 @Bean
 public Client client()
{
    return new ApacheHttpClient();
}

@Bean
public FeignClientErrorDecoder errorDecoder()
   {
    return new FeignClientErrorDecoder( new FeignDecoder() );
   }

 }
 

FeignClient构建器:

  public <T> T build( Class<T> clazz,String url,RequestInterceptor interceptor,FallbackFactory<T> fallbackFactory )
{
    return HystrixFeign.builder()
                       .logLevel( Logger.Level.FULL )
                       .client( client )
                       .encoder( encoder )
                       .decoder( decoder )
                       .retryer( retryer )
                       .contract( contract )
                       .errorDecoder( errorDecoder )
                       .requestInterceptor( interceptor )
                       .target( clazz,url,fallbackFactory );

}
  @FeignClient( name = "http-client",configuration = FeignConfiguration.class,decode404 = true,fallbackFactory = NotificationFeignFallbackFactory.class )
  public interface NotificationFeignClient
  {
    @PostMapping( produces = APPLICATION_JSON_VALUE )
    <T> CompletableFuture<ResponseEntity<?>> doSend( @Valid @RequestBody T data );

  }

当我得到回应时,我会遇到类似这样的异常:

  feign.codec.DecodeException: Error while extracting response for type                      
  [java.util.concurrent.CompletableFuture<org.springframework.http.ResponseEntity<?>>]
  and content type [application/json]; nested exception is               
  org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error:  
  Unrecognized token 'Body': was expecting (JSON String,Number,Array,Object or token 
  'null','true' or 'false'); nested exception is  
  com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'Body': was expecting 
  (JSON String,Object or token 'null','true' or 'false')
  at [Source: (pushbackinputstream); line: 1,column: 5]

就我而言,我想解析对CompletableFuture的响应。我该怎么办?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)