1

I'm using FeignClient in spring boot. I have some issues.

My config file is:

@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 builder:

  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 );

  }

When I get response , I have got exceptions like this :

  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, Number, Array, Object or token 'null', 'true' or 'false')
  at [Source: (PushbackInputStream); line: 1, column: 5]

In my case I want to parse response to CompletableFuture. How can I do it?

  • I noticed you are using Generics at NotificationFeignClient. Can you confirm the type that you are using matches with the returned response? `JSON parse error: Unrecognized token 'Body': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')` probably means you do not have the correct schema for the response type. – gtiwari333 Oct 27 '20 at 17:42
  • You can use tools like https://www.site24x7.com/tools/json-to-java.html if you are not sure how to model the json in java class – gtiwari333 Oct 27 '20 at 17:43
  • I'm using any type to return like Object, String,JSON,... You are right! I am using Generic types to send and receive data – Nasibulloh Yandashev Oct 28 '20 at 20:15
  • You can use JsonNode instead of Object if you don't want to write the POJO type – gtiwari333 Oct 29 '20 at 00:46

0 Answers0